1 / 15

Module 33

Module 33. Pushdown Automata (PDA’s) Another example. Palindromes. Let PAL be the set of palindromes over {a,b} Let PAL1 be the following related language: {wcw r | w consists only of a’s and b’s} we add c to the input alphabet as a special “marker” character Strings in PAL1

judith-holt
Download Presentation

Module 33

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module 33 • Pushdown Automata (PDA’s) • Another example

  2. Palindromes • Let PAL be the set of palindromes over {a,b} • Let PAL1 be the following related language: • {wcwr | w consists only of a’s and b’s} • we add c to the input alphabet as a special “marker” character • Strings in PAL1 • aca, bcb, abcba, aabcbaa, c • strings not in PAL1 • aaca, aaccaa, abccba, abcb, abba • Let PAL2 be the set of even length palindromes • {wwr | w consists only of a’s and b’s}

  3. PAL1 • Lets first construct a PDA for PAL1 • Basic ideas • Have one state remember first “half” of string • Have one state “match” second half of string to first half • Transition between these two states when the first c is encountered

  4. PDA for PAL1 • M = (Q, S, G, q0, Z, A, d) • Q = {q0, qm, qf} • S = {a, b, c} • G = {Z, a, b} • q0 = q0 • Z = Z • A = {qf}

  5. Transition Function Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q0 a Z q0 aZ 2 q0 a a q0 aa 3 q0 a b q0 ab 4 q0 b Z q0 bZ 5 q0 b a q0 ba 6 q0 b b q0 bb 7 q0 c Z qm Z 8 q0 c a qm a 9 q0 c b qm b 10 qm a a qml 11 qm b b qml 12 qml Z qf Z First three transitions push a on top of the stack Second three transitions push b on the stack Third three transitions switch state q0 to qm No change to stack Transitions 10 and 11 “match” characters from first and last half of input string

  6. Notation comment Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q0 a Z q0 aZ 2 q0 a a q0 aa 3 q0 a b q0 ab 4 q0 b Z q0 bZ 5 q0 b a q0 ba 6 q0 b b q0 bb 7 q0 c Z qm Z 8 q0 c a qm a 9 q0 c b qm b 10 qm a a qml 11 qm b b qml 12 qml Z qf Z • We might represent transition 1 in two other ways • d(q0,a,Z) = (q0, aZ) • (q0, a, Z, q0, aZ) • Question • Is this PDA deterministic?

  7. (q0, bcba, aZ) (q0, cba, baZ) (qm, ba, baZ) (qm, a, aZ) (qm, l, Z) (qf, l, Z) Computation Graph 1 Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q0 a Z q0 aZ 2 q0 a a q0 aa 3 q0 a b q0 ab 4 q0 b Z q0 bZ 5 q0 b a q0 ba 6 q0 b b q0 bb 7 q0 c Z qm Z 8 q0 c a qm a 9 q0 c b qm b 10 qm a a qml 11 qm b b qml 12 qml Z qf Z (q0, abcba, Z)

  8. (q0, bcab, aZ) (q0, cab, baZ) (qm, ab, baZ) Computation Graph 2 Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q0 a Z q0 aZ 2 q0 a a q0 aa 3 q0 a b q0 ab 4 q0 b Z q0 bZ 5 q0 b a q0 ba 6 q0 b b q0 bb 7 q0 c Z qm Z 8 q0 c a qm a 9 q0 c b qm b 10 qm a a qml 11 qm b b qml 12 qml Z qf Z (q0, abcab, Z)

  9. (q0, cab, aZ) (qm, ab, aZ) (qm, b, Z) (qf, b, Z) Computation Graph 3 Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q0 a Z q0 aZ 2 q0 a a q0 aa 3 q0 a b q0 ab 4 q0 b Z q0 bZ 5 q0 b a q0 ba 6 q0 b b q0 bb 7 q0 c Z qm Z 8 q0 c a qm a 9 q0 c b qm b 10 qm a a qml 11 qm b b qml 12 qml Z qf Z (q0, acab, Z)

  10. PAL2 • Lets now construct a PDA for PAL • What is harder this time? • When do we switch from putting strings on the stack to matching? • Example • After seeing aab, should we switch to match mode or stay in stack mode? • Solution • Do both using nondeterminism

  11. PDA for PAL2 • M = (Q, S, G, q0, Z, A, d) • Q = {q0, qm, qf} • S = {a, b} • G = {Z, a, b} • q0 = q0 • Z = Z • A = {qf}

  12. Transition Relation Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q0 a Z q0 aZ 2 q0 a a q0 aa 3 q0 a b q0 ab 4 q0 b Z q0 bZ 5 q0 b a q0 ba 6 q0 b b q0 bb 7 q0l Z qm Z 8 q0l a qm a 9 q0l b qm b 10 qm a a qml 11 qm b b qml 12 qml Z qf Z First three transitions push a on top of the stack Second three transitions push b on the stack Third three transitions switch state q0 to qm Is the PDA deterministic or nondeterministic?

  13. (q0, bba, aZ) (qm, abba, Z) (q0, ba, baZ) (qm, bba, aZ) (qf, abba, Z) (q0, a, bbaZ) (qm, ba, baZ) (q0, l, abbaZ) (qm, a, aZ) (qm, a, bbaZ) (qm, l, Z) (qm, l, abbaZ) (qf, l, Z) Computation Graph 1 Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q0 a Z q0 aZ 2 q0 a a q0 aa 3 q0 a b q0 ab 4 q0 b Z q0 bZ 5 q0 b a q0 ba 6 q0 b b q0 bb 7 q0l Z qm Z 8 q0l a qm a 9 q0l b qm b 10 qm a a qml 11 qm b b qml 12 qml Z qf Z (q0, abba, Z)

  14. (q0, ba, aZ) (qm, aba, Z) (q0, a, baZ) (qm, ba, aZ) (qf, aba, Z) (q0, l, abaZ) (qm, a, baZ) (qm, l, abaZ) Computation Graph 2 Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q0 a Z q0 aZ 2 q0 a a q0 aa 3 q0 a b q0 ab 4 q0 b Z q0 bZ 5 q0 b a q0 ba 6 q0 b b q0 bb 7 q0l Z qm Z 8 q0l a qm a 9 q0l b qm b 10 qm a a qml 11 qm b b qml 12 qml Z qf Z (q0, aba, Z)

  15. PAL • Challenge • Construct a PDA for PAL • First step • Construct a PDA for odd length palindromes • Then • Combine PDA’s for odd length and even length palindromes

More Related