210 likes | 332 Views
L ECTURE 10 Theory of Computation Review Constructing PDAs Turing Machines. Intro to Theory of Computation. CS 464. Sofya Raskhodnikova. Context-free or not?. L₁ = { xy | x,y ∈ {0,1}* and x=y}. NOT. YES. L₂ = {xy | x,y ∈ {0,1}*, |x|=|y| and x ≠ y}.
E N D
LECTURE10 • Theory of Computation • Review • Constructing PDAs • Turing Machines Intro to Theory of Computation CS 464 Sofya Raskhodnikova Sofya Raskhodnikova; based on slides by Nick Hopper
Context-free or not? L₁ = { xy | x,y ∈ {0,1}* and x=y} NOT YES L₂ = {xy | x,y ∈ {0,1}*, |x|=|y| and x ≠ y}
Give an algorithmic description of a PDA for and but Hint:
Give an algorithmic description of a PDA for and but Hint:
CMPSC 464 so far First model of a program: DFA / Regexp Solvable Problems: Regular Languages Unsolvable Problems: { 0n1n | n ¸ 0 } Next model of a program: PDA / CFG Solvable Problems: Context-Free Languages Unsolvable Problems: { w#w | w 2* } defis_duplicate(s): n = len(s)/2 if (s[n]!=‘#’): return False return s[:n] == s[n+1:]
FINITE STATE CONTROL TURING MACHINE (TM) q0 q1 I N P U T A UNBOUNDED (on the right) TAPE
qreject read write move → , R 0 → 0, R qaccept 0→ 0, R → , R 0→ 0, R → , L A TM can loop forever
TM versus PDA TM can both write to and read from the tape The head can move left and right The input does not have to be read entirely Accept and Reject take immediate effect Infinite tape on the right, stick on the left TM is deterministic (will consider NTMs later)
STATE Testing membership in B = { w#w | w {0,1}* } q1, FIND qGO LEFT q1, FIND # q0, FIND # q#, FIND q0, FIND x x 0 0 x 0 1 0 1 # 1 # 1 1 1
Definition of a TM A TM is a 7-tuple T = (Q, Σ, Γ, , q0, qaccept, qreject): Q is a finite set of states Σ is the input alphabet, where Σ Γ is the tape alphabet, where Γ and Σ½Γ : Q Γ→ Q Γ {L,R} q0 Q is the start state qaccept Q is the accept state qreject Q is the reject state, and qreject qaccept
q7 0 0 0 1 1 1 0 1 1 0 CONFIGURATIONS 11010q700110
qreject x → x, L 2n 0 → 0, L { 0 | n ≥ 0 } q2 → , R → , L x → x, R x → x, R q0 q1 q3 0 → , R 0 → x, R x → x, R 0 → 0, R → , R 0 → x, R → , R qaccept q4 x → x, R → , R
x → x, L 2n 0 → 0, L { 0 | n ≥ 0 } q2 → , R → , L x → x, R x → x, R q0 q1 q3 0 → , R 0 → x, R x → x, R 0 → 0, R → , R qreject 0 → x, R → , R qaccept q4 x → x, R → , R q00000 q1000 xq300 x0q40 x0xq3 x0q2x xq20x q2x0x q2x0x
Accepting and rejecting A TM on input sting w may either halt (enter qacceptorqreject) or never halt (loop) A TM is a decider if it halts on every input.
Language of a TM A TM recognizesa language L if it accepts all strings in L and no other strings. • A language is called recognizable (or enumerable) if some TM recognizes it. A TM decides a language L if it accepts all strings in L and rejects all strings not in L. • A language is called decidable(or recursive) if some TM decides it.