Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.

Similar presentations


Presentation on theme: "Introduction to the Theory of Computation John Paxton Montana State University Summer 2003."— Presentation transcript:

1 Introduction to the Theory of Computation John Paxton Montana State University Summer 2003

2 Humor A little boy, who wanted $100.00 very badly, prayed for two weeks but nothing happened. Then he decided to write GOD a letter requesting $100.00. When the postal authorities received the letter to GOD, U.S.A., they decided to send it to the President. The President was so impressed, touched, and amused that he instructed his secretary to send the boy $50.00. Mr. President thought that this would appear to be a lot of money to the little boy. The little boy was delighted with the $50.00 and immediately sat down to write a thank you note to GOD that read: "Dear God, Thank you very much for sending me the money. However, I noticed that for some reason you had to send it through Washington, D.C., and, as usual, those devil's took half of it.

3 2.2 Pushdown Automata Fundamentally, an NFA with a stack A recognizer Equivalent to a Context Free Grammar A CFG is a generator

4 PDA Definition A PDA is a 6-tuple (Q, , Γ, ,q 0, F) where 1.Q is the set of states  is the input alphabet 3.Γ is the stack alphabet  : Q x   x Γ   P(Q x Γ  ) is transition 5.q 0 is the start state 6.F ≤ Q is the set of accept states

5 Acceptance A pushdown automaton M accepts input w if w can be written w 1 w 2 …w m where each w i    and states r 0,r 1,…r m  Q and strings s 0, s 1, … s m  Γ* exist that satisfy 1.r 0 = q 0 and s 0 =  2.(r i+1, b)   (r i, w i+1, a) where s i = at and s i+1 = bt 3.r m  F

6 Example 1 Q = {q 1, q 2, q 3, q 4 } S = {0, 1} F = {0, $} F = {q 1, q 4 } d(q 1, ,  ) = (q 2, $) d(q 2, 0,  ) = (q 2, 0) d(q 2, 1, 0) = (q 3,  ) d(q 3, 1, 0) = (q 3,  ) d(q 3, , $) = (q 4,  )

7 Example 1 q1q1 q2q2 q3q3 q4q4 ,  -> $ 0,  -> 0 1, 0 ->  , $ -> 

8 Exercise Show a PDA that recognizes the language {a i b j c k | i, j, k >= 0 and i = j or j = k}. Draw a picture. Show it formally, (Q, , Γ, ,q 0, F).

9 Exercise Show a PDA that recognizes the language { ww R | w  {0,1}* Draw a picture. Show it formally.

10 Theorem: PDAs and CFGs are equivalent Part 1: If a language is context free, then some pushdown automaton recognizes it. Part 2: If a pushdown automaton recognizes some language, then it is context free.

11 Part 1 q start q loop q accept ,  -> S$ , $ ->  , A -> w (for rule A -> w) a, a ->  (for terminal a)

12 Part 1 What about a rule such as A -> aBc? q loop ,A -> c ,  -> B ,  -> a

13 Exercise Construct a PDA that is equivalent to the following CFG S -> aTb | b T -> Ta | 

14 Part 2 Construct the PDA such that 1.It has a single accept state q accept 2.It empties its stack before accepting 3.Each transition either pushes a symbol onto the stack (a push move) or pops one off the stack (a pop move), but does not do both at the same time.

15 Construction The start variable is q 0 q accept The variables are q i q j if  (p, a,  ) contains (r, t) and  (s, b, t) contains (q,  ), then add q p q q -> aq rs b add q pq -> q pr q rq for all p, q, r add q pp ->  for all p

16 Example 1, revisited q1q1 q2q2 q3q3 q4q4 ,  -> $ 0,  -> 0 1, 0 ->  , $ -> 

17 Example 1, CFG q 11 -> , q 22 -> , etc. q 11 -> q 11 q 11 | q 12 q 21 | q 13 q 31 | q 14 q 41 q 14 ->  q 23  q 23 -> 0q 23 1 Example derivation: q 14 -> q 23 -> 0q 23 1 -> 00q 23 11 -> 0011

18 Corollary Every regular language is context free regular languages context-free languages


Download ppt "Introduction to the Theory of Computation John Paxton Montana State University Summer 2003."

Similar presentations


Ads by Google