Download presentation
Presentation is loading. Please wait.
Published byCameron Sims Modified over 6 years ago
1
CS 461 – Sept. 28 Section 2.2 – Pushdown Automata { 0n 1n }
Palindromes Equal Next: Converting CFG PDA
2
{ 0n 1n } While reading 0s, push them.
If you read 1, change state. Then, as you read 1s, pop 0s off the stack. Watch out for bad input! Unspecified transition crash (reject) Now, let’s write this in the form of a table.
3
POP & Go to state “reading 1”
PDA δ for { 0n 1n } State Reading 0 Reading 1 Tos (don’t care) Empty Input 1 Action Push 0 POP & Go to state “reading 1” Crash Pop Notes: Action depends on input symbol AND what’s on top of stack. Action includes manipulating stack AND/OR changing state.
4
Example #2 { w # wR } (easier form of palindrome)
Let’s design a PDA that accepts its input by empty stack, as before. Think about: state, top-of-stack, input, action
5
PDA δ for { w # wR } Before # After # (don’t care) 1 # State Tos Input
1 Input # Action Push 0 Push 1 Go to “after #” Pop Crash
6
Palindrome PDA? Before # After # (don’t care) 1 # State Tos Input
1 Input # Action Push 0 Push 1 Go to “after #” Pop Crash Changes needed: Non-deterministically go to “after #” when you push 0 or 1. Also, non-deterministically don’t push, in case we are dealing with odd-length palindrome!
7
Other examples Think about these “equal” language More 1s than 0s.
How many states do we need? … More 1s than 0s. Twice as many 1s as 0s. Hint: think of the 0s as counting double.
8
Equal PDA State (Just one state) Tos ε 1 Input Action Push 0 Push 1
1 Input Action Push 0 Push 1 Pop
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.