Classwork You may work with a partner. What's the Time Complexity of M? M = "On input string w: 1. Scan the tape from left to right looking for a's. If no a is found, go to step 5. If an a is found, continue with step 2. 2. Scan to the right end of the a's and replace the last a with blank. 3. Return to the left of the tape and replace the first a with X. 4. Go to step 1. 5. Return the head to the left end of the tape. 6. Scan from left to right, changing every X into an a. 7. Accept." Time Complexity Classes What's a Time Complexity Class? a set of languages that can be decided in the same amount of time What's a formal definition of a Time Complexity Class? TIME(t(n)) = { L | L is a language decided by a O(t(n)) time TM } What are common Time Complexity Classes? TIME(1) TIME(log n) TIME(n) TIME(n log n) TIME(n^2) TIME(n^3) TIME(2^n) The machine M1 decides the language A in O(n^2) time. A = { 0^k 1^k | k >= 0 } M1 = "On input string w: 1. Scan the tape; reject if a 0 is found to the right of a 1. 2. Repeat line 3 while both 0s and 1s remain on the tape. 3. Scan the tape; cross off a single 0 and a single 1. 4. If no 0s and no 1s remain on the tape, accept, otherwise reject." Which Time Complexity Class is the language A found in? Can you build a machine that decides A more quickly? What happens if you cross off two 0s and two 1s on each scan? You need to cross off more than a constant number on each scan. Can you cross off half the 0s and half the 1s on each scan? Does the Turing Machine M2 decide A? M2 = "On input string w: 1. Scan the tape; reject if a 0 is found to the right of a 1. 2. Repeat lines 3,4 while both 0s and 1s remain on the tape. 3. Scan the tape; reject if the total number of 0s and 1s is odd. 4. Scan the tape; cross off every other 0 and every other 1. 5. If no 0s and no 1s remain on the tape, accept, otherwise reject." Why is line 3 needed in M2? consider the string: 00011 (becomes 01 after first pass) What's the Time Complexity of M2? Which additional Time Complexity Class is the language A found in? What happens when you use more tapes? Does the Turing Machine M3 decide A? M3 = "On input string w: 1. Scan the tape; reject if a 0 is found to the right of a 1. 2. Copy the 0s from tape 1 to tape 2. 3. Scan the 1s on tape 1. For each 1 read, cross off a 0 on tape 2. If all the 0s are crossed off before all the 1s are read, reject. 4. If all the 0s are crossed off tape 2, accept, otherwise reject." What's the Time Complexity of M3? Is the language A found in yet another Time Complexity Class? Complexity Relationships between Computational Models What's the Church-Turing Thesis? Does Decidability depend on variations in the computation model? Does the number of tapes or nondeterminism affect Decidability? Does Complexity depend on variations in the computation model? Does the number of tapes or nondeterminism affect Complexity? If a Multi-tape TM uses t(n) time, how long does it take to simulate a single Multi-tape TM step on a Single-tape TM? each Multi-tape step uses O(p) time where p is the length of the active part of the tape the length of the active part of the tape is O(t(n)) If a Multi-tape TM uses t(n) time, what's an upper bound on the time needed by an equivalent Single-tape TM? an equivalent Single-tape TM uses at most O(t(n)^2) time What's the Time Complexity of a Nondeterministic Turing Machine? given a nondeterministic TM M that halts on all inputs the time complexity of M is function f:N -> N f(n) is the maximum number of steps M uses on any branch on any length-n input If a Nondeterministic TM uses t(n) time, how much time is needed to simulate a single branch of the NTMs execution on a Deterministic TM? each branch is O(t(n)) If a Nondeterministic TM uses t(n) time, what's an upper bound on the number of branches of execution it can have? it can have at most b^t(n) branches where b is the maximum number of choices given by the transitions If a Nondeterministic TM uses t(n) time, what's an upper bound on the time needed by an equivalent Deterministic TM? an equivalent deterministic TM uses at most 2^O(t(n)) time