Goal of Chapters 1-5: Analyze what problems can be solved, in theory
Goal of Chapter 7: Analyze what problems can be solved, in a reasonable amount of time
DTM M halts on all inputs
Let f(n): N → N be the maximum number of steps M uses on w when |w| = n
We say M is an f(n) time TM, ie M runs in time f(n)
Many times we don't care about the exact function f
Example: Time Complexity of TM M is O(n2) means
Examples of Big O notation:
Why do we care about Big O
Assume input size of n
Polynomial time complexity:
Exponential time complexity:
Theorem 7.8: Every t(n) time multitape TM has an equivalent O(t2(n)) time single-tape TM. (Assuming function t(n) must be t(n) ≥ n.)
This is a polynomial increase in speed
Def. 7.9: N is a NTM that is a decider. The running time of N is the function f(n), the maximum number of steps than N uses in any branch of its computation of any input of length n.
See Figure 7.10
Th. 7.11: Every t(n) NTM has an equivalent 2O(t(n)) time deterministic TM. In both cases, the machines are single tape, and t(n) ≥ n.
This is an exponential increase in speed
P is the class of languages that are decidable in polynomial time on a deterministic single-tape TM.
P = ∪ TIME(nk), for all k
P is the same for all models of computation that are polynomially equivalent to the deterministic TM.
P is roughly the same as the class problems that can be realistically solved on a computer.
Remember: Decidable in polynomial time
PATH = {<G, s, t>| Directed graph G has a path from s to t}
Theorem 7.14: PATH ∈ P
Proof of Theorem 7.14: M = On input <G, s, t>, where G is a directed graph with nodes s and t:
Use an adjacency matrix (ie table with a row and column for each node) to implement the matrix
We must decide a given input in polynomial time
For input of size n:
The number of stages must be polynomial number in n
The number of steps per stage must be polynomial number in n
Assumption: Encoding of input must be done in polynomial time wrt to the input size
We describe algorithms, but they could be Turing Machines.
RELPRIME = {<x, y>| s and t are relatively prime}
Theorem 7.15: RELPRIME ∈ P
Proof of Theorem 7.15: E = On input <x, y>, where x and y are natural numbers in binary:
R = On input <x, y>, where x and y are natural numbers in binary:
Each stage of E (except possible the first) at least halves the size of x
Theorem 7.16: Every CFL is decidable in polynomial time.
Is the CFL decidable language fast enough? No.
Sketch of proof of Theorem 7.16: E = On input w = w1 ... wn:
Assume grammar is in CNF
Build a table of all derivable substrings of w
If start symbol S is in the table, the string is derivable
O(n3) algorithm
Building from partial solutions is called *dynamic programming
Each stage of E (except possible the first) at least halves the size of x