Constructing a PDA for
PDA basics: formal definition and how to construct one
We want a push-down automaton (PDA) that recognizes the language So each accepted string has the form:
- a prefix over ,
- then one symbol ,
- then a string over ,
- then one symbol ,
with the constraint that the length of equals the length of .
Key terms: pushdown automaton , stack alphabet , stack discipline , configuration.
High-level construction idea
Use the stack to count (in unary) how many symbols are in .
- While reading the prefix (unknown length), push one stack symbol per read input symbol.
- When the PDA decides it has reached the middle symbol , it switches to a “matching” phase where it reads the part and pops one stack symbol per symbol of .
- Finally, after is fully matched (stack empty), it must read the last symbol and accept.
This works because “” is exactly the condition “we popped once for each symbol pushed.”
The PDA will be nondeterministic about where ends (i.e., where it decides to read the distinguished middle ).
Pro Tip: nondeterministically guess the split
Since the PDA cannot know ahead of time, it uses nondeterminism to guess which input symbol is the fixed middle 'a' (the boundary between and ).
Formal PDA definition
We construct a PDA that accepts by final state.
- where:
- is the initial stack bottom marker
- is used as one “unit” per symbol of
- Start state:
- Initial stack symbol:
- Final states:
We define by transitions (below). Notation: .
PDA behavior (push $u$, pop $w$, then read the ending $b$)
- 1Step 1
In state , for each input symbol or (while still building ), push one onto the stack for that symbol.
- 2Step 2
At some point, nondeterministically choose to consume an input as the distinguished middle symbol. Then switch to .
- 3Step 3
In , for each input symbol or consumed as part of , pop exactly one from the stack.
- 4Step 4
When the next symbol after matching is processed, require that the stack top is (meaning all pushed units have been popped).
- 5Step 5
With stack top , consume the final input symbol and transition to .
Transition function
We now list transitions that implement the above behavior.
1) Push phase:
For :
These transitions push one for every consumed symbol of .
2) Guess the middle : switch to pop phase
On reading the distinguished middle symbol , do:
- (allowed only if could be empty)
Interpretation: we consume that but do not pop anything at the boundary; we only pop during the phase.
3) Pop phase: match length of to length of
For :
This pops one per symbol of .
4) After , require stack empty (top is ) and read final
This ensures:
- we have consumed the final ,
- and the stack has no remaining (so ).
Common pitfall: accepting too early
If you allowed acceptance whenever the stack becomes empty without consuming the final 'b', you could accept strings not of the exact form . The transition that consumes 'b' from with stack top prevents that.
Why this PDA recognizes exactly
Soundness ():
Assume accepts some string. Acceptance requires reaching via the transition that consumes the final when the stack top is . That implies:
- all pushed during reading have been popped during reading , so ,
- exactly one middle symbol was consumed to switch from push to pop,
- and the last consumed symbol is . Thus the input is with and .
Completeness ():
Given any string with , the PDA can:
- push one per symbol in ,
- nondeterministically choose the correct position of the middle (the one shown),
- then pop one per symbol of ,
- and finally read the ending when stack top is . So the PDA has an accepting run.
Key terms: nondeterminism , acceptance by final state , unary counting with stack.
Visual summary (state machine view)
Length constraint enforced by stack push/pop
Each symbol of contributes one ; each symbol of pops one . Acceptance requires the stack to be empty before consuming the final .
FAQ / Edge cases
Knowledge Check
In the construction, what does the PDA push for each symbol read during the -prefix?