Theory of Computation Lecture Notes
Theory of Computation Lecture Notes
Prof. Yuh-Dauh Lyuu Dept. Computer Science & Information Engineering and Department of Finance National Taiwan University
Page 1
Class Information
Papadimitriou. Computational Complexity. 2nd printing. Addison-Wesley. 1995. The best book on the market for graduate students. We more or less follow the topics of the book. More advanced materials may be added. Check www.csie.ntu.edu.tw/~lyuu/complexity/2003 for last years lecture notes. You may want to review discrete mathematics.
Page 2
Page 3
Grading
No roll calls. No homeworks. Try some of the exercises at the end of each chapter.
Two to three examinations. You must show up for the examinations, in person. If you cannot make it to an examination, please email me beforehand (unless there is a legitimate reason). Missing the nal examination will earn a fail grade.
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Page 10
Page 11
Page 12
Page 13
Page 14
I have never done anything useful. Godfrey Harold Hardy (18771947), A Mathematicians Apology (1940)
Page 15
Page 16
Page 17
Page 18
Growth of Factorials
n 1 2 3 4 5 6 7 8 n! 1 2 6 24 120 720 5040 40320 n 9 10 11 12 13 14 15 16 n! 362,880 3,628,800 39,916,800 479,001,600 6,227,020,800 87,178,291,200 1,307,674,368,000 20,922,789,888,000
Page 19
Page 20
Turing Machines
Page 21
What Is Computation?
That can be coded in an algorithm. An algorithm is a detailed step-by-step method for solving a problem. The Euclidean algorithm for the greatest common divisor is an algorithm. Let s be the least upper bound of compact set A is not an algorithm. Let s be a smallest element of a nite-sized array can be solved by an algorithm.
Page 22
Turing Machinesa
A Turing machine (TM) is a quadruple M = (K, , , s). K is a nite set of states. s K is the initial state. is a nite set of symbols (disjoint from K). includes (blank) and (rst symbol). : K (K {h, yes, no}) {, , } is a transition function. (left), (right), and (stay) signify cursor movements.
a Turing
(1936).
Page 23
A TM Schema
1000110000111001110001110
Page 24
Physical Interpretations
The tape: computer memory and registers. : program. K: instruction numbers. s: main() in C. : alphabet much like the ASCII code.
Page 25
More about
The program has the halting state (h), the accepting state (yes), and the rejecting state (no). Given current state q K and current symbol , (q, ) = (p, , D). It species the next state p, the symbol to be written over , and the direction D the cursor will move afterwards. We require (q, ) = (p, , ) so that the cursor never falls o the left end of the string.
Page 26
The cursor is pointing to the rst symbol, always a . The TM takes each step according to . The cursor may overwrite during the computation. to make the string longer
Page 27
Program Count
A program has a nite size. Recall that : K (K {h, yes, no}) {, , }. So |K| || lines suce to specify a program, one line per pair from K . Given K and , there are ((|K| + 3) || 3)|K||| possible s (see next page). This is a constantalbeit large. Dierent s may dene the same behavior.
Page 28
(| K | + 3) | | 3 possibilities
Page 29
The Halting of a TM
A TM M may halt in three cases. yes: M accepts its input x, and M (x) = yes.
no: M rejects its input x, and M (x) = no. h: M (x) = y, where the string consists of a , followed by a nite string y, whose last symbol is not , followed by a string of s. y is the output of the computation. y may be empty denoted by . If M never halts on x, then write M (x) = .
Page 30
Why TMs?
Because of the simplicity of the TM, the model has the advantage when it comes to complexity issues. One can develop a complexity theory based on C++ or Java, say. But the added complexity does not yield additional fundamental insights. We will describe TMs in pseudocode.
Page 31
Page 32
Congurations (concluded)
A conguration is a triple (q, w, u): q K. w is the string to the left of the cursor (inclusive). u is the string to the right of the cursor. Note that (w, u) describes both the string and the cursor position.
Page 33
1000110000111001110001110
w = 1000110000. u = 111001110001110.
Page 34
Yielding
Fix a TM M . Conguration (q, w, u) yields conguration (q , w , u ) in one step, (q, w, u) (q , w , u ), if a step of M from conguration (q, w, u) results in conguration (q , w , u ). (q, w, u) (q , w , u ): Conguration (q, w, u) yields conguration (q , w , u ) in k N steps. (q, w, u) (q , w , u ): Conguration (q, w, u) yields conguration (q , w , u ).
M Mk M
Page 35
Page 36
Palindromes
A string is a palindrome if it reads the same forwards and backwards (e.g., 001100). A TM program can be written to recognize palindromes: It matches the rst character with the last character. It matches the second character with the next to last character, etc. (see next page). yes for palindromes and no for nonpalindromes. This program takes O(n2 ) steps. Can we do better?
Page 37
100011000000100111
Page 38
Page 39
100011000000100111
Cut
yes/no
Page 40
Page 41
Then C(y, y) = C(x, y) by the cut-and-paste argument (see next page). Hence P(x, y) has the same answer as P(y, y)! So C(x, x) is distinct for each x.
Page 42
xr
yr
yr
Page 43
x{0,1}m
Page 44
distinct C(x, x)s with | C(x, x) | . The rest must have | C(x, x) | > . Because C(x, x) is distinct for each x (p. 42), there are m+1 at least 2m 2 m of them with | C(x, x) | > .
Page 45
| C(x, x) | > =
| C(x, x) |
2m+1 2 m m2 2m . m
m
| C(x, x) | = (m2m ).
(1)
Page 46
yes/no
Page 47
T (n) is the worst-case running time spent in the middle section when dealing with any P (x, x) with | x | = m.
m i=1
| Ci (x, x) |.
Page 48
T (n)
x{0,1}m i=1 m
| Ci (x, x) | | Ci (x, x) |.
i=1 x{0,1}m
Page 49
2m T (n) . | Ci (x, x) | m m
| Ci (x, x) | = (m2m ).
Hence
a Dirichlet
Page 50