Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages – Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA – Regular Expressions and Regular Grammars CS 301 - Lecture 27 – Properties of Regular Languages – Languages that are not regular and the pumping lemma • Context Free Languages Complexity – Context Free Grammars – Derivations: leftmost, rightmost and derivation trees – Parsing, Ambiguity, Simplifications and Normal Forms – Nondeterministic Pushdown Automata – Pushdown Automata and Context Free Grammars – Deterministic Pushdown Automata – Pumping Lemma for context free grammars – Properties of Context Free Grammars Fall 2008 • Turing Machines – Definition, Accepting Languages, and Computing Functions – Combining Turing Machines and Turing’s Thesis – Turing Machine Variations, Universal Turing Machine, and Linear Bounded Automata – Recursive and Recursively Enumerable Languages, Unrestricted Grammars – Context Sensitive Grammars and the Chomsky Hierarchy • Computational Limits and Complexity – Computability and Decidability – Complexity Example: Given a set of n numbers x1, x2, …, xn is number y in the set? Algorithm to answer this: • If x = x1, stop and answer yes Computational Complexity • If x = x2, stop and answer yes • If x = x3, stop and answer yes • ….. • If x = xn, stop and answer yes • Answer no. Time Required depends on n worst case requires n compares Let’s formalize this idea… 1
Time Complexity Time Complexity: The number of steps during a computation • Model Computation Using Turing machine • We count the number of steps until a string is accepted Space used Space Complexity: during a computation • We use the O(n) notation n n L { a b : n 0 } n n = ≥ Example: L { a b : n 0 } = ≥ Time needed: Algorithm to accept a string : w O (| w |) • Copy the on the second tape a • Use a two-tape Turing machine • Compare the and a b O (| w |) • Copy the on the second tape a • Compare the and a b Total time: O (| w |) 2
n n L { a b : n 0 } Language class: DTIME ( n ) = ≥ DTIME ( n ) n For string of length L L 1 3 L 2 O ( n ) time needed for acceptance: A Deterministic Turing Machine accepts each string of length n in time O ( n ) In a similar way we define the class DTIME ( n ) DTIME ( T ( n )) for any time function: T ( n ) n n { a b : n 0 } ≥ 2 3 Examples: DTIME ( n ), DTIME ( n ),... 3
Example: The membership problem k 1 k + Theorem: DTIME ( n ) DTIME ( n ) ⊂ for context free languages L = { w : w is generated by grammar G } k 1 + DTIME ( n ) ( 3 L ∈ DTIME n ) (CYK - algorithm) ( k DTIME n ) Polynomial time Example: The Satisfiability Problem ( k Polynomial time algorithms: DTIME n ) Boolean expressions in Conjunctive Normal Form: t t t t ∧ ∧ ∧ ∧ 1 2 3 k Represent tractable algorithms: Variables For small we can compute the k t x x x x = ∨ ∨ ∨ ∨ i 1 2 3 p result fast Question: is expression satisfiable? 4
Example: Example: ( x x ) ( x x ) ( x x ) ( x x ) ∨ ∧ ∨ ∨ ∧ ∨ 1 2 1 3 1 2 1 3 Satisfiable? Satisfiable: x 0 , x 1 , x 1 = = = 1 2 3 Can you find values for x1, x2, and x3 so that ( x x ) ( x x ) 1 ∨ ∧ ∨ = 1 2 1 3 ( x x ) ( x x ) 1 ∨ ∧ ∨ = 1 2 1 3 ( x x ) x x ( x x ) x x Example: Example: ∨ ∧ ∧ ∨ ∧ ∧ 1 2 1 2 1 2 1 2 Satisfiable? Can you find values for x1, x2, and x3 so that Not satisfiable 5
( n L = { w : expression w is satisfiabl e} Exponential time algorithms: DTIME 2 ) Algorithm: search exhaustively all the possible binary values of the variables Represent intractable algorithms: Some problem instances may take centuries to solve For variables, combinations to try n Exponential, can we do better? The satisfiability problem Example: L = { w : expression w is satisfiabl e} L = { w : expression w is satisfiabl e} Time for variables: n • Guess an assignment of the variables O ( n ) Non-Deterministic algorithm: • Guess an assignment of the variables • Check if this is a satisfying assignment O ( n ) • Check if this is a satisfying assignment Total time: O ( n ) 6
Example: L = { ww } Non-Determinism Language class: NTIME ( n ) Non-Deterministic Algorithm to accept a string : ww NTIME ( n ) • Use a two-tape Turing machine L 1 L 3 L 2 • Guess the middle of the string A Non-Deterministic Turing Machine and copy on the second tape w accepts each string of length n in time O ( n ) • Compare the two tapes L = { ww } Time needed: NTIME ( n ) • Use a two-tape Turing machine L = { ww } • Guess the middle of the string O (| w |) and copy on the second tape w • Compare the two tapes O (| w |) Total time: O (| w |) 7
In a similar way we define the class Non-Deterministic Polynomial time algorithms: NTIME ( T ( n )) T ( n ) for any time function: ( k L ∈ NTIME n ) 2 3 Examples: NTIME ( n ), NTIME ( n ),... Selecting the “Right” Machine Selecting the “Right” Machine • Model Computation Using Turing machine • If a two-tape machine takes steps, a one • But the choice of machine seems to tape machine can simulate this in matter a great deal! • Two tapes machines might take fewer steps than one tape machines • If a non-deterministic machine takes steps, a deterministic one can simulate • Non-Deterministic machines might take fewer steps than Deterministic ones this in • Is there a “right” choice to make? So do we need classes for each machine type?? 8
What’s Next • Read – Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, 7.2, 7.3, (skip 7.4), 8, 9, 10, 11, 12.1, 12.2, (skip 12.3, 12.4, 12.5, 13), 14.1, 14.2, and 14.3 – JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7, (skip 8), 9, (skip 10), 11 • Next Lecture Topics from 14.4 - 14.7 – P, NP, Reductions, and NP-complete problems • Quiz 4 Wednesday 12/3 – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you like. • Homework – Homework 13 Due Today – Homework 14 Due Thursday – Homework 15 Due Tuesday 12/9 – Homework 16 = study for the final!! 9
Recommend
More recommend