Exercises — Pushdown automata (PDA) — configuration, acceptance by empty stack - final state
A tiny reminder of the pieces you will keep using (so you never hit an undefined symbol):
Whenever a step below shows , it means: the rule fired — input lost its front symbol , and the stack-top was replaced by (leaving the tail untouched). Each ⊢ in this page is annotated with the exact rule and its justification.
Level 1 — Recognition
Exercise 1.1 (L1)
State whether each is true or false: (a) A PDA configuration records the input already read. (b) In acceptance by empty stack, the set of final states is irrelevant. (c) The top of the stack is written as the rightmost symbol of .
Recall Solution 1.1
(a) False. The configuration stores only the remaining unread input . Already-read input cannot affect the future, so it is deliberately dropped. (b) True. — the condition is "stack empty," not "state in ." (c) False. By convention the top is leftmost. In , symbol is on top and is the tail below it.
Exercise 1.2 (L1)
Given a PDA with , , , name which of the following are valid shapes for an output of (a member of ): (a) (b) (c) (d)
Recall Solution 1.2
must return a finite set of pairs . (a) Valid — a set with one pair . (b) Invalid — it is a bare pair, not a set. Correct form: . (c) Valid — two pairs (nondeterministic choice: pop, or leave one ). (d) Invalid — is a set of states, missing the pushed string.
Level 2 — Application
Exercise 2.1 (L2)
Using the empty-stack PDA for (rules 1–4 below), write the full ID sequence for the string and confirm acceptance.
Recall Solution 2.1
Rules: (1) , (2) , (3) , (4) . Each step names the rule that fires and why it is the only legal one. Why each is forced: with top and next input , only rule 1 applies; with top and next , only rule 2; with top and next , only rule 3; with input exhausted and top , only rule 4. Stack empty, input fully read ⇒ accepted. The maximum stack height was (the three 's plus ).
Exercise 2.2 (L2)
Take the final-state version (rules 1–3, plus 4': , ). Run it on . Then explain, with an ID, why is rejected.
Recall Solution 2.2
Accepting run on (each ⊢ labelled with the firing rule):
and input is exhausted ⇒ accept (stack still holds , which is fine — final-state mode ignores the stack).
Rejecting : Now we are in state with unread input and top . There is no rule (rule 4' needs -input, not ) — the machine is stuck with input remaining. It never reaches having read all input, so . Correct: has one but two 's. ✓
Level 3 — Analysis
Exercise 3.1 (L3)
A student claims a PDA accepts by empty stack using:
- ,
- ,
Trace and decide if the design is correct.
Recall Solution 3.1
Idea: each pushes two 's (so we owe two 's per ); each pops one . Label each ⊢:
Two 's pushed 's; four 's popped all ; marker-pop empties the stack. The design is correct. Max stack height reached: ( + ).
Check the guard: a bad string like would push then pop once on the single , leaving — non-empty, no more moves, rejected, as required.
Exercise 3.2 (L3)
Explain precisely why the empty-stack PDA in Exercise 2.1 would wrongly accept the empty string if we dropped the "" restriction — i.e. trace what happens on input .
Recall Solution 3.2
Start configuration on empty input: . Rule 4 () applies immediately, because its -input needs no letter and its required top is present: The stack empties with no input consumed, so is accepted. But has , which our language excludes. So this PDA actually recognises . To exclude you must force at least one before the marker can be popped — e.g. only allow the marker-pop from a distinct "seen-a-then-b" state.
Level 4 — Synthesis
Exercise 4.1 (L4)
Design a PDA (empty stack) for . Give the transitions and explain the counting logic.
Recall Solution 4.1
Since , every must be cancelled by exactly one later symbol ( or ). Push one per ; pop one per , then one per . Use states to enforce the order . States , start , stack alphabet .
- , — push per .
- — the escape (see WHY below).
- , — pop per , lock into -phase.
- , , — pop per .
- , — pop marker when all 's gone ⇒ empty stack.
WHY the rule does not misfire: its required top is , which — in state — is only exposed in two situations: (i) at the very start before any is read, or (ii) never again once an has pushed an , because from then on the top is (not ) until every is popped, and popping 's can only happen in states or , never back in . So in state the marker is re-exposed only on the truly empty input. That is exactly the case (the empty string, which satisfies ), so accepting it is correct, and it cannot "eat" the marker in the middle of a real string. The order-enforcing states help here too: once we leave we never return, so this rule is inert during the - and -phases.
Why it works overall: total pops ; total pushes . The stack empties (after the marker pop) iff . Ordering states guarantee 's precede 's precede 's. Test (): push , pop on , pop on , pop ⇒ empty ⇒ accept. ✓ Test (): , so after one leftover remains on the stack ⇒ not empty ⇒ rejected. ✓
Exercise 4.2 (L4)
Convert the empty-stack PDA of Exercise 2.1 into an equivalent final-state PDA using the fresh-bottom-marker trick. Give the new tuple pieces.
Recall Solution 4.2
What "fresh " means and how it differs from : is the old machine's bottom marker — the symbol whose disappearance signalled "stack empty ⇒ accept." is a brand-new symbol added to that appears in no old rule (that is what "fresh" means: it is not used anywhere else, so no existing transition can touch it). We place below as the true bottom. Now is no longer the bottom — it is an ordinary symbol the old rules manipulate, while sits underneath, guaranteeing the stack is never physically empty during simulation.
Construction. Add a fresh start state and a fresh final state .
- New start: , new initial stack symbol .
- — push the old start symbol above , jump to old start state .
- Keep old rules 1–3 unchanged.
- Replace old rule 4 with (pop , exactly as the old machine emptied), then
- — when the fresh marker finally surfaces, go to final state .
- .
WHY the freshness matters: the old machine accepted precisely by reaching a physically empty stack. If we only bolted on a final state without , then (a) at the accept moment there would be no top symbol left to trigger the -move into , and (b) any partial run that emptied the stack early could be misinterpreted. Because is fresh (untouched by old rules) and sits at the very bottom, the only moment is ever exposed is exactly when the old run would have emptied — no sooner. So .
Level 5 — Mastery
Exercise 5.1 (L5)
The palindrome language needs nondeterminism. Give an empty-stack PDA and show both a computation branch that accepts and a branch (guessing the wrong midpoint) that dies.
Recall Solution 5.1
States (push phase, pop phase), stack .
- Push phase: for , any top — push each read symbol.
- Guess midpoint: — nondeterministically switch to popping.
- Pop phase: — pop only if top equals current input (match).
- — empty the marker ⇒ accept.
Accepting branch on (guess midpoint after 2 symbols), each ⊢ labelled:
Dying branch (guess midpoint too early, after 1 symbol):
Now top is but next input is ; the pop rule requires top equal to the input, and , so no rule exists ⇒ this branch is stuck with input left and dies. Since acceptance requires some branch to succeed, and the correct-midpoint branch does, .
Reading the figure below. It draws these two branches side by side: the shared push of the first at the top, then the split. The left (orange) path guesses the midpoint after exactly two symbols and walks all the way down to — accept. The right (plum) path guesses one symbol too early; its next required pop compares top against input , finds no matching rule, and terminates (labelled "DIES"). The picture makes visible why the guess must land on the true centre: only then do the popped symbols line up with the remaining input.

Exercise 5.2 (L5)
Prove that no deterministic PDA (DPDA) can accept , in intuition (not full formalism), tying it to why Exercise 5.1 needed a guess.
Recall Solution 5.2
First, the precise constraints that define a DPDA (these are the formal WHY):
- Single-move restriction: for every triple with , — at most one legal move. There is no set of alternatives to explore.
- No competing -move: if then for every input symbol . So a DPDA can never choose between "read a letter" and "make a silent move" on the same top symbol.
- One-symbol window: a single move sees only the next one input symbol and the single top-of-stack symbol — no lookahead further into the input.
Consequence for : to recognise it the machine must flip from pushing the first half to matching the second half exactly at the midpoint. But the midpoint is unmarked: reading , after ab the machine cannot tell whether it stands at the true centre or is still inside the first half (the string could equally have continued as ). Constraint 3 forbids peeking ahead to resolve this; constraints 1–2 forbid trying both possibilities. So a DPDA is forced to commit to one guess with a single deterministic path — and for the family of strings where the centre is genuinely ambiguous, whichever it commits to is wrong on some input.
A nondeterministic PDA escapes precisely because it is allowed multiple moves (its may return a set): Exercise 5.1's -move coexists with the push move on the same top symbol, letting it split off a "guess the midpoint here" branch at every position at once. One branch guesses correctly and accepts. Because a DPDA cannot make that guess, separates the classes: it is a language of PDAs but not of DPDAs, proving DPDA ⊊ PDA. This is unlike finite automata, where the subset construction (Nondeterministic Finite Automata) makes DFA = NFA — the stack blocks that trick. Compare with Context-Free Grammars: every CFL has some PDA, but not necessarily a deterministic one.
Recall Quick self-check ladder
L1: top of stack is written where in ? ::: Leftmost. L2: does final-state acceptance require an empty stack? ::: No — it ignores stack contents. L3: what accidental string does a bare -marker-pop accept? ::: (empty string). L4: what does the fresh marker prevent in empty→final conversion? ::: Accidental early emptying / false accept (and it gives a top symbol to trigger the accept move). L5: why can't a DPDA do ? ::: It cannot guess the unmarked midpoint (single move, no competing -move, one-symbol window).
Connections
- Parent: PDA topic note
- Grammar side: Context-Free Grammars, Closure Properties of CFLs
- Limits & separations: Deterministic PDA (DPDA), Pumping Lemma for CFLs
- Neighbours in the hierarchy: Nondeterministic Finite Automata, Turing Machines