Upload
moshe
View
44
Download
0
Embed Size (px)
DESCRIPTION
Measuring Complexity. Lecture 36 Section 7.1 Fri, Nov 16, 2007. Time Complexity Classes. Let t : N R + be a function. The time complexity class TIME( t ( n )) is the set of all languages that are decidable by an O ( t ( n )) Turing machine. Examples. SHIFT is in TIME( n ). - PowerPoint PPT Presentation
Citation preview
Measuring Complexity
Lecture 36Section 7.1
Fri, Nov 16, 2007
Time Complexity Classes
• Let t : N R+ be a function.• The time complexity class
TIME(t(n)) is the set of all languages that are decidable by an O(t(n)) Turing machine.
Examples
• SHIFT is in TIME(n).• COPY is in TIME(n2).• INCR and DECR are in TIME(n).• If ADD uses INCR and DECR, then
what is the time complexity class of ADD?
• If MULT uses ADD, then what is the time complexity class of MULT?
Integer Factorization
• Let the input be an n-bit integer k.• Suppose a Turing machine uses
the following strategy to factor the integer.• Divide k by each integer from 2 to k –
1.• Assume division requires constant
time.
Integer Factorization
• What will be the run time of this machine?
Single Tape vs. Multitape
• Theorem: If a problem P is in TIME(t(n)) for k-tape Turing machine and t(n) n, then it is in TIME(t2(n)) for a single-tape Turing machine.
Single Tape vs. Multitape
• Proof:• The single-tape equivalent S of the
multitape machine M records the contents of the k tapes of M on its single tape.
• That requires O(n) steps.• In the t(n) transitions of M, it can scan
at most t(n) cells of each of its tapes. Call that the “active” portion.
Single Tape vs. Multitape
• For each transition of S:•S scans the tape once to determine the
current symbol on each tape.• The time required by the scan is at most k t(n) = O(t(n)).
• Then S simulates on each portion of its tape the action of M on each of its tapes.
• That action may require shifting right all remaining cells.
Single Tape vs. Multitape
• Each shift requires up to time t(n).• The time required is at most
t(n) O(t(n)) = O(t2(n)).• The total is
O(n) + O(t2(n)) = O(t2(n)).
Deterministic vs. Nondeterministic
• Theorem: If a problem P is in TIME(t(n)) for a nondeterministic Turing machine, then it is in TIME(2O(t(n))) for a deterministic Turing machine.
Deterministic vs. Nondeterministic
• Proof:• Let N be a nondeterministic Turing
machine that decides P.• Consider a tree whose branches
represent the different possible execution paths of N.
• Let b be the largest number of branches at any node of the tree.
Deterministic vs. Nondeterministic
• No path through the tree can have length greater than t(n).
• So the total number of leaves is no greater than bt(n).
• A deterministic Turing machine D will do a breadth-first search of the tree, searching for the accept state.
Deterministic vs. Nondeterministic
• For every node searched, D begins at the root node and follows the path to that node.
• That requires time at most t(n).• The number of nodes is less than
twice the number of leaves.• So there are at most 2bt(n) nodes.
Deterministic vs. Nondeterministic
• The total search time required is at most O(t(n)(2bt(n))) = O(bO(t(n))).
• So D is in TIME(bO(t(n))).• Finally, D is a 3-tape machine.• It can be simulated by a single-tape
machine that is in TIME((bO(t(n)))2) = TIME(2O(t(n))).
Example
• The factoring problem can be solved nondeterministically in O(n) time, where n equals the length of the number. (How?)
• Therefore, the factoring problem can be solved deterministically in O(2O(n)) time.