Lecture 31: Efficiency in computation
Instructor: S. Akshay
IITB, India
Spring 2020
Recap
Turing machines and computability 1. Turing machines
(i) Definition (ii) Variants
(iii) Decidable and Turing recognizable languages (iv) Church-Turing Hypothesis
2. Undecidability
(i) A proof technique by diagonalization (ii) Via reductions
3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages
Recap
Turing machines and computability 1. Turing machines
(i) Definition (ii) Variants
(iii) Decidable and Turing recognizable languages (iv) Church-Turing Hypothesis
2. Undecidability
(i) A proof technique by diagonalization (ii) Via reductions
(ii) A problem for compilers: Unambiguity of Context-free languages
Recap
Turing machines and computability 1. Turing machines
(i) Definition (ii) Variants
(iii) Decidable and Turing recognizable languages (iv) Church-Turing Hypothesis
2. Undecidability
(i) A proof technique by diagonalization (ii) Via reductions
3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages
This lecture
Efficiency in computation
I Resource bounded Turing machines I Measuring run-time complexity I Computability and complexity
I The polynomial time complexity class
Reading Material
I Section 10.1, Introduction to Automata Theory, Languages and Computation, Hopcroft, Motwani and Ullman
I Section 7.1, 7.2, Introduction to the Theory of Computation, Michael Sipser
This lecture
Efficiency in computation
In this lecture we will cover
I Resource bounded Turing machines I Measuring run-time complexity I Computability and complexity
I The polynomial time complexity class
Reading Material
I Section 10.1, Introduction to Automata Theory, Languages and Computation, Hopcroft, Motwani and Ullman
I Section 7.1, 7.2, Introduction to the Theory of Computation, Michael Sipser
Turing machines with Resource constraints
What resources do Turing machines use?
I Space/memory I Time
I Cost I Energy
I What else? number of times a state is visited, number of tape reversals, number of writes
Why consider resources? I TMs are algorithms...
I Decidability does not implementability!
Turing machines with Resource constraints
What resources do Turing machines use?
Resources for computation:
I Space/memory I Time
I Cost I Energy
I What else? number of times a state is visited, number of tape reversals, number of writes
Why consider resources? I TMs are algorithms...
I Decidability does not implementability!
Turing machines with Resource constraints
What resources do Turing machines use?
Resources for computation:
I Space/memory I Time
I Cost I Energy I What else?
Why consider resources? I TMs are algorithms...
I Decidability does not implementability!
Turing machines with Resource constraints
What resources do Turing machines use?
Resources for computation:
I Space/memory I Time
I Cost I Energy
I What else? number of times a state is visited, number of tape reversals, number of writes
Why consider resources? I TMs are algorithms...
I Decidability does not implementability!
What resources do Turing machines use?
Resources for computation:
I Space/memory I Time
I Cost I Energy
I What else? number of times a state is visited, number of tape reversals, number of writes
Why consider resources?
I TMs are algorithms...
I Decidability does not implementability!
Running Time Complexity
Given M a halting TM,running time of M is the function
f(n) :N→N, which counts the maximum number of steps that M uses on any input of length n.
Given M a halting TM,running time of M is the function
f(n) :N→N, which counts the maximum number of steps that M uses on any input of length n.
Is this the only notion possible? Any others?
Running Time Complexity
Given M a halting TM,running time of M is the function
f(n) :N→N, which counts the maximum number of steps that M uses on any input of length n.
I Worst-case complexity - longest running time of all inputs of lengthn (in this course, we consider this)
I Average-case complexity - average running time over all inputs of length n.
Let f,g :B→R+, we sayg(n) is an (asymptotic) upper bound for f(n), denoted
f(n) =O(g(n))if ∃c,n0 ∈Z+ s.t∀n ≥n0,f(n)≤c ·g(n).
I f is less than or equal to g up to a constant factor.
I why use this? to estimate instead of precise.
A recap of Big O and small o notation
Let f,g :B→R+, we sayg(n) is an (asymptotic) upper bound for f(n), denoted
f(n) =O(g(n))if ∃c,n0 ∈Z+ s.t∀n ≥n0,f(n)≤c ·g(n).
Let f,g :B→R+, we write f(n) = o(g(n))if ∀c >0,∃n0 s.t ∀n≥n0, f(n)≤c·g(n), i.e., limn→∞ f(n)
g(n) = 0.
I more like strictly less than (asymptotically)
Let f,g :B→R+, we sayg(n) is an (asymptotic) upper bound for f(n), denoted
f(n) =O(g(n))if ∃c,n0 ∈Z+ s.t∀n ≥n0,f(n)≤c ·g(n).
Let f,g :B→R+, we write f(n) = o(g(n))if ∀c >0,∃n0 s.t ∀n≥n0, f(n)≤c·g(n), i.e., limn→∞ f(n)
g(n) = 0.
Exercises: True or false
1. 234n3+ 345n2−3 =O(n3) 2. 84n3+ 4n4+ 3 =O(n5) 3. n=o(nloglogn)
4. 2O(n) =o(n242345325)
5. O(n) +nO(n) +O(n) =O(n2)
A recap of Big O and small o notation
Let f,g :B→R+, we sayg(n) is an (asymptotic) upper bound for f(n), denoted
f(n) =O(g(n))if ∃c,n0 ∈Z+ s.t∀n ≥n0,f(n)≤c ·g(n).
Let f,g :B→R+, we write f(n) = o(g(n))if ∀c >0,∃n0 s.t ∀n≥n0, f(n)≤c·g(n), i.e., limn→∞ f(n)
g(n) = 0.
Exercises: True or false
1. 234n3+ 345n2−3 =O(n3) 2. 84n3+ 4n4+ 3 =O(n5) 3. n=o(nloglogn)
4. 2O(n) =o(n242345325)
5. O(n) +n2O(n) +O(n) =O(n2)
polynomial: nc for c >0, exponential: 2nδ,δ >0.
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
Running Time Complexity
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
TIME(t(n))is set of all languages decidable by a O(t(n)) TM
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
TIME(t(n))is set of all languages decidable by a O(t(n)) TM
Exercise: Is A={0k1k |k ≥0}in O(n2)?
Running Time Complexity
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
TIME(t(n))is set of all languages decidable by a O(t(n)) TM
Exercise: Is A={0k1k |k ≥0}in O(n2)?
1. scan tape once to check if input is of form 0∗1∗. else reject.
2. repeat until there are no 0’s:
3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)
4. at end if there are 1’s remaining reject, otherwise, accept.
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
TIME(t(n))is set of all languages decidable by a O(t(n)) TM
Exercise: Is A={0k1k |k ≥0}in O(n2)?
1. scan tape once to check if input is of form 0∗1∗. else reject.O(n) steps 2. repeat until there are no 0’s:
3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)
4. at end if there are 1’s remaining reject, otherwise, accept.
Running Time Complexity
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
TIME(t(n))is set of all languages decidable by a O(t(n)) TM
Exercise: Is A={0k1k |k ≥0}in O(n2)?
1. scan tape once to check if input is of form 0∗1∗. else reject.O(n) steps 2. repeat until there are no 0’s:
3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)O(n) steps
4. at end if there are 1’s remaining reject, otherwise, accept.
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
TIME(t(n))is set of all languages decidable by a O(t(n)) TM
Exercise: Is A={0k1k |k ≥0}in O(n2)?
1. scan tape once to check if input is of form 0∗1∗. else reject.O(n) steps 2. repeat until there are no 0’s: n/2 repetitions
3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)O(n) steps
4. at end if there are 1’s remaining reject, otherwise, accept.
Running Time Complexity
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
TIME(t(n))is set of all languages decidable by a O(t(n)) TM
Exercise: Is A={0k1k |k ≥0}in O(n2)?
1. scan tape once to check if input is of form 0∗1∗. else reject.O(n) steps 2. repeat until there are no 0’s: n/2 repetitions
3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)O(n) steps
4. at end if there are 1’s remaining reject, otherwise, accept. O(n) steps
Let t :N→R+. A language L⊆Σ∗ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ∗ of length n,M halts on x within time O(t(n)).
TIME(t(n))is set of all languages decidable by a O(t(n)) TM
Exercise: Is A={0k1k |k ≥0}in O(n2)?
1. scan tape once to check if input is of form 0∗1∗. else reject.O(n) steps 2. repeat until there are no 0’s: n/2 repetitions
3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)O(n) steps
4. at end if there are 1’s remaining reject, otherwise, accept. O(n) steps Overall: O(n) +nO(n) +O(n) =O(n2) steps
Running Time Complexity (Contd.)
TIME(t(n))is set of all languages decidable by a O(t(n)) Turing machine
Questions
I IsA={0k1k |k ≥0}in o(n2)?
I IsA in O(n)?
TIME(t(n))is set of all languages decidable by a O(t(n)) Turing machine
Questions
I IsA={0k1k |k ≥0}in o(n2)?
I IsA in O(n)?
Does crossing two 0s and 1s on every scan instead of just one help?
Running Time Complexity (Contd.)
TIME(t(n))is set of all languages decidable by a O(t(n)) Turing machine
Questions
I IsA={0k1k |k ≥0}in o(n2)?
I IsA in O(n)?
I Scan tape and reject, if 0 is to right of 1.
I Scan the 0s and copy them to another tape, until first 1.
I Scan 1s in first tape together with 0s in second tape, if 0’s are crossed before 1s are read, reject
I if all 0s are crossed off at the end, accept, else reject.
TIME(t(n))is set of all languages decidable by a O(t(n)) Turing machine
Questions
I IsA={0k1k |k ≥0}in o(n2)?
I IsA in O(n)?
I Scan tape and reject, if 0 is to right of 1.
I Scan the 0s and copy them to another tape, until first 1.
I Scan 1s in first tape together with 0s in second tape, if 0’s are crossed before 1s are read, reject
I if all 0s are crossed off at the end, accept, else reject.
Running Time Complexity (Contd.)
TIME(t(n))is set of all languages decidable by a O(t(n))1-tapeTuring machine
Questions
I (HW)Is A={0k1k |k ≥0}in o(n2)?
I IsA in O(n)?
I Scan tape and reject, if 0 is to right of 1.
I Scan the 0s and copy them to another tape, until first 1.
I Scan 1s in first tape together with 0s in second tape, if 0’s are crossed before 1s are read, reject
I if all 0s are crossed off at the end, accept, else reject.
So, with 2-tape can improve “complexity”. Can we improve with 1-tape?
TIME(t(n))is set of all languages decidable by a O(t(n))1-tapeTuring machine
Questions
I (HW)Is A={0k1k |k ≥0}in o(n2)?
I (Challenge)IsA in O(n)?
So, with 2-tape can improve “complexity”.
Running Time Complexity (Contd.)
TIME(t(n))is set of all languages decidable by a O(t(n))1-tapeTuring machine
Questions
I (HW)Is A={0k1k |k ≥0}in o(n2)?
I (Challenge)IsA in O(n)?
So, with 2-tape can improve “complexity”.
Conclusion: change of model can change complexity, even if it does not change computability.
Computability vs Complexity
I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.
I Complexity: Choice of model affects running time.
Complexity between models of computation
Computability vs Complexity
I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.
I Complexity: Choice of model affects running time.
Our goal
Computability vs Complexity
I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.
I Complexity: Choice of model affects running time.
Our goal
I to measure or classify problems by their (running) time complexity
Complexity between models of computation
Computability vs Complexity
I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.
I Complexity: Choice of model affects running time.
Our goal
I to measure or classify problems by their (running) time complexity I But if change of model changes complexity, then how can we measure or
classify them?
Computability vs Complexity
I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.
I Complexity: Choice of model affects running time.
Our goal
I to measure or classify problems by their (running) time complexity I But if change of model changes complexity, then how can we measure or
classify them?
I Fortunately, it doesn’t change by much, at least for deterministic models!
Complexity between models of computation
Computability vs Complexity
I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.
I Complexity: Choice of model affects running time.
Our goal
I to measure or classify problems by their (running) time complexity I But if change of model changes complexity, then how can we measure or
classify them?
I Fortunately, it doesn’t change by much, at least for deterministic models!
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Multi-tape to single tape
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS:
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.
I To simulate one-step of M,
Multi-tape to single tape
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.
I To simulate one-step of M,
I S scans all info on its tape to check all head positions
I then makes another pass over tape to update tape contents and head positions.
I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right.
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,
I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head
positions. O(t(n))steps
I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right.
Multi-tape to single tape
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,
I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head
positions. O(t(n))steps
I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right. k tapes =k heads=k×O(t(n))steps
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,O(t(n))
I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head
positions. O(t(n))steps
I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right. k tapes =k heads=k×O(t(n))steps
Multi-tape to single tape
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,O(t(n))
I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head
positions. O(t(n))steps
I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right. k tapes =k heads=k×O(t(n))steps
I t(n) steps ofM impliest(n)×O(t(n)) =O(t2(n)) steps
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.
Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,O(t(n))
I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head
positions. O(t(n))steps
I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right. k tapes =k heads=k×O(t(n))steps
I t(n) steps ofM impliest(n)×O(t(n)) =O(t2(n)) steps I Overall: O(n) +O(t2(n)) =O(t2(n)) (since t(n)≥n)
What about non-determinism?
Running time of a non-det halting TM
The running time of a non-det halting TM N is the function f(n:N→N), where f(n) is the max number of steps that N uses on any branch of its computation on any input of length n.
Theorem
Lett(n) be a function such that t(n)≥n. Then everyt(n) time non-det 1-tape TMN has an equivalent2O(t(n)) timedet 1-tape TMD.
I Recall that computation of N is viewed as a tree. I Each branch is of length at most t(n).
I What is the max number of leaves of the tree? bt(n) where b is from transition fn.
I What is the max number of nodes of tree?less than twice no. of leaves. I Do bfs on tree – what is the complexity of this? O(bt(n)) = 2O(t(n)). I three tapes to one-tape: (2O(t(n)))2 = 2O(t(n)).
What about non-determinism?
Running time of a non-det halting TM
The running time of a non-det halting TM N is the function f(n:N→N), where f(n) is the max number of steps that N uses on any branch of its computation on any input of length n.
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time non-det 1-tape TM N has an equivalent2O(t(n)) timedet 1-tape TMD.
I Each branch is of length at most t(n).
I What is the max number of leaves of the tree? bt(n) where b is from transition fn.
I What is the max number of nodes of tree?less than twice no. of leaves. I Do bfs on tree – what is the complexity of this? O(bt(n)) = 2O(t(n)). I three tapes to one-tape: (2O(t(n)))2 = 2O(t(n)).
What about non-determinism?
Running time of a non-det halting TM
The running time of a non-det halting TM N is the function f(n:N→N), where f(n) is the max number of steps that N uses on any branch of its computation on any input of length n.
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time non-det 1-tape TM N has an equivalent2O(t(n)) timedet 1-tape TMD.
I Recall that computation of N is viewed as a tree.
I Each branch is of length at most t(n).
I What is the max number of leaves of the tree?
bt(n) where b is from transition fn.
I What is the max number of nodes of tree?less than twice no. of leaves. I Do bfs on tree – what is the complexity of this? O(bt(n)) = 2O(t(n)). I three tapes to one-tape: (2O(t(n)))2 = 2O(t(n)).
What about non-determinism?
Running time of a non-det halting TM
The running time of a non-det halting TM N is the function f(n:N→N), where f(n) is the max number of steps that N uses on any branch of its computation on any input of length n.
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time non-det 1-tape TM N has an equivalent2O(t(n)) timedet 1-tape TMD.
I Recall that computation of N is viewed as a tree.
I Each branch is of length at most t(n).
I What is the max number of leaves of the tree? bt(n) where b is from transition fn.
I What is the max number of nodes of tree?
I Do bfs on tree – what is the complexity of this? O(b ) = 2 . I three tapes to one-tape: (2O(t(n)))2 = 2O(t(n)).
What about non-determinism?
Running time of a non-det halting TM
The running time of a non-det halting TM N is the function f(n:N→N), where f(n) is the max number of steps that N uses on any branch of its computation on any input of length n.
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time non-det 1-tape TM N has an equivalent2O(t(n)) timedet 1-tape TMD.
I Recall that computation of N is viewed as a tree.
I Each branch is of length at most t(n).
I What is the max number of leaves of the tree? bt(n) where b is from transition fn.
I What is the max number of nodes of tree?less than twice no. of leaves.
I Do bfs on tree – what is the complexity of this?
O(bt(n)) = 2O(t(n)). I three tapes to one-tape: (2O(t(n)))2 = 2O(t(n)).
Running time of a non-det halting TM
The running time of a non-det halting TM N is the function f(n:N→N), where f(n) is the max number of steps that N uses on any branch of its computation on any input of length n.
Theorem
Let t(n) be a function such that t(n)≥n. Then everyt(n) time non-det 1-tape TM N has an equivalent2O(t(n)) timedet 1-tape TMD.
I Recall that computation of N is viewed as a tree.
I Each branch is of length at most t(n).
I What is the max number of leaves of the tree? bt(n) where b is from transition fn.
I What is the max number of nodes of tree?less than twice no. of leaves.
I Do bfs on tree – what is the complexity of this? O(bt(n)) = 2O(t(n)).
The class P
So, k-tape to 1-tape involves a polynomial blow-up, while non-det to det requires an exponential blow-up.
Definition
P is the class of languages that are decidable in polynomial time on a deterministic single-tape Turing machine, i.e.,
P =[
k
TIME(nk)
Why important
I take all models of computation that are polytime eq to det 1-tape TM, P is invariant.
I classically considered to be the good class for a computer. Examples:
I Given a graph G, is there a path froms to t? I Are two given numbers relatively prime?
The class P
So, k-tape to 1-tape involves a polynomial blow-up, while non-det to det requires an exponential blow-up.
Definition
P is the class of languages that are decidable in polynomial time on a deterministic single-tape Turing machine, i.e.,
P =[
k
TIME(nk)
Why important
I take all models of computation that are polytime eq to det 1-tape TM, P is invariant.
I classically considered to be the good class for a computer.
I Are two given numbers relatively prime?
The class P
Definition
P is the class of languages that are decidable in polynomial time on a deterministic single-tape Turing machine, i.e.,
P =[
k
TIME(nk)
Why important
I take all models of computation that are polytime eq to det 1-tape TM, P is invariant.
I classically considered to be the good class for a computer.
Examples:
I Given a graph G, is there a path froms to t?
I Are two given numbers relatively prime?
Definition
P is the class of languages that are decidable in polynomial time on a deterministic single-tape Turing machine, i.e.,
P =[
k
TIME(nk)
Why important
I take all models of computation that are polytime eq to det 1-tape TM, P is invariant.
I classically considered to be the good class for a computer.
Examples:
I Given a graph G, is there a path froms to t?
Examples of problems in P
PATH: Given directed graph G = (V,E) and nodes s,t, is there a path between s and t
PATH: Given directed graph G = (V,E) and nodes s,t, is there a path between s and t
Brute force algo?
Examples of problems in P
PATH: Given directed graph G = (V,E) and nodes s,t, is there a path between s and t
I Mark s
I Repeat until no additional nodes are marked:
I scan all edges ofG and if (a,b) is an edge with amarked andb unmarked, then markb,
I if t is marked, accept, else reject.
PATH: Given directed graph G = (V,E) and nodes s,t, is there a path between s and t
I Mark s
I Repeat until no additional nodes are marked: at most|V|times I scan all edges ofG and if (a,b) is an edge with amarked andb
unmarked, then markb,
I if t is marked, accept, else reject.
Examples of problems in P
PATH: Given directed graph G = (V,E) and nodes s,t, is there a path between s and t
RELPRIME: Given x,y ∈N, is gcd(x,y) = 1
PATH: Given directed graph G = (V,E) and nodes s,t, is there a path between s and t
RELPRIME: Given x,y ∈N, is gcd(x,y) = 1 Euclid’s algo!
I repeat till y= 0;
I assign x:=x mod y I exchange x and y;
I At end if result is x= 1 accept, else reject.
Examples of problems in P
PATH: Given directed graph G = (V,E) and nodes s,t, is there a path between s and t
RELPRIME: Given x,y ∈N, is gcd(x,y) = 1 Euclid’s algo!
I repeat till y= 0;how many times is this done?
I assign x:=x mod y I exchange x and y;
I At end if result is x= 1 accept, else reject.
The class EXP
Definition
EXP is the class of languages that are decidable in exponential time on a deterministic single-tape Turing machine, i.e.,
EXP =[
k
TIME(2nk)
I AllP time problems! i.e.,P ⊆EXP.
I HAMILTONIAN-PATH: G,s,t: is there a path froms tot that goes through each node of G exactly once?
I (Generalized) CHESS
I COMPOSITIES: is a number composite?
The class EXP
Definition
EXP is the class of languages that are decidable in exponential time on a deterministic single-tape Turing machine, i.e.,
EXP =[
k
TIME(2nk)
Examples
I AllP time problems! i.e.,P ⊆EXP.
I HAMILTONIAN-PATH: G,s,t: is there a path froms tot that goes through each node of G exactly once?
I (Generalized) CHESS
I COMPOSITIES: is a number composite?
The class EXP
Definition
EXP is the class of languages that are decidable in exponential time on a deterministic single-tape Turing machine, i.e.,
EXP =[
k
TIME(2nk)
Examples
I AllP time problems! i.e.,P ⊆EXP.
I (Generalized) CHESS
I COMPOSITIES: is a number composite?
The class EXP
Definition
EXP is the class of languages that are decidable in exponential time on a deterministic single-tape Turing machine, i.e.,
EXP =[
k
TIME(2nk)
Examples
I AllP time problems! i.e.,P ⊆EXP.
I HAMILTONIAN-PATH: G,s,t: is there a path froms tot that goes through each node of G exactly once?
I (Generalized) CHESS
I COMPOSITIES: is a number composite?
The class EXP
Definition
EXP is the class of languages that are decidable in exponential time on a deterministic single-tape Turing machine, i.e.,
EXP =[
k
TIME(2nk)
Examples
I AllP time problems! i.e.,P ⊆EXP.
I HAMILTONIAN-PATH: G,s,t: is there a path froms tot that goes through each node of G exactly once?
I (Generalized) CHESS
The class EXP
Definition
EXP is the class of languages that are decidable in exponential time on a deterministic single-tape Turing machine, i.e.,
EXP =[
k
TIME(2nk)
Examples
I AllP time problems! i.e.,P ⊆EXP.
I HAMILTONIAN-PATH: G,s,t: is there a path froms tot that goes through each node of G exactly once?
I (Generalized) CHESS
I COMPOSITIES: is a number composite?