4.6.10 · D2Theory of Computation

Visual walkthrough — Pushdown automata (PDA) — configuration, acceptance by empty stack - final state

2,032 words9 min readBack to topic

This page is a visual companion to the parent PDA note. If you've seen Nondeterministic Finite Automata, picture that machine — then imagine handing it a stack of plates.


Step 1 — A machine with a memory made of plates

WHAT. Before any formula, meet the object. A PDA is a small brain (finitely many moods, called states) plus one tall column of stacked plates — the stack. It reads a strip of letters left to right.

WHY. The parent note's headline is "a PDA is an NFA bolted onto a stack." A plain finite machine can only remember which of finitely many moods it's in — it can't count how many a's it saw if there could be a million. A stack fixes exactly that: you can add a plate for each a, and the pile grows as tall as you need. That unbounded-but-LIFO (Last In, First Out — you can only touch the top plate) memory is the one thing that lifts a PDA above regular languages.

PICTURE. The red column is the stack. Only the top plate is reachable. The input strip runs left→right; a reading head sits over the next unread letter.


WHAT. A single move takes one configuration to the next. The parent writes it as the yields relation (read "yields"): if the rulebook allows as a response to seeing state , input letter , top plate , then

WHY term by term — this is the heartbeat of the machine, so we annotate every piece:

  • : the mood changes.
  • : the letter is consumed — it vanishes from the front of the unread input.
  • : the top plate is replaced by the string ; everything below () is untouched.

PICTURE. Watch the only plate that moves: the red top one. Below it, sits frozen. The letter is crossed off the strip.


Step 3 — Watch a real run empty its stack:

WHAT. Take the language (some a's then equally many b's). The plan: push one plate per a, pop one plate per b. If the counts match, the plates vanish together. We trace the input .

WHY this language. It is the smallest thing a finite machine cannot do — it must count. The stack height is the count. When we finish, the stack tells us whether the counts balanced.

PICTURE. Read the run left→right; the red number tracks stack height. It rises on a, falls on b, and touches the floor at the very end.

Term by term on the last step : input is already (all read), the bottom marker is popped (replaced by ), stack becomes truly empty. Here is the initial stack symbol, the single plate that sits on the floor before anything happens — our "bottom marker."


Step 4 — The FIRST way to say "you passed": empty the stack

WHAT. Acceptance by empty stack: the input is accepted exactly when, after reading everything, no plates remain. Here means "in zero or more steps," is the start mood, and the final means no input left, no plates left. The mood at the end is irrelevant.

WHY it works. In Step 3 the stack hit zero precisely when a's balanced b's. The emptiness of the stack is the certificate that the structure matched.

PICTURE. Two runs side by side: aabb drains to an empty floor (accept); aab leaves one red plate stranded (reject — one unmatched a).


Step 5 — The SECOND way: land in a happy mood (final state)

WHAT. Acceptance by final state: pick a special set of "happy" moods. Accept iff you finish reading input in some mood inside whatever is on the stack. The here is any leftover stack; it is simply ignored.

WHY the difference matters. For we don't dump ; instead, when only the marker remains we hop to a happy mood and stop. The plates can stay on the table.

PICTURE. Same drain, but the accept test is a green flag on the mood, and the leftover plate is greyed to show "we don't care about it."


Step 6 — Convert empty-stack → final-state (the fresh floor trick)

WHAT. Given a machine that accepts by empty stack, build that accepts by final state and recognizes the same language.

WHY it's subtle. If we just said "accept when the stack empties," we can't see emptiness from inside — the moment the last plate leaves, there's nothing to trigger a transition. The fix: slip a brand-new bottom plate under everything at the start. When empties its plates, becomes visible — that exposure is our signal to jump to a happy mood.

PICTURE. The red is the new floor. 's real stack sits above it. When 's plates are gone, pokes out and we flip to .

Construction, annotated:

  • Add fresh start mood with push 's marker above our new floor , then run .
  • Add happy mood , with for every mood whenever surfaces (⇒ 's stack was empty), go happy.
  • Set .

The floor guarantees can never accidentally reach a truly empty stack early — the only bare- moment is exactly when genuinely emptied.


Step 7 — Convert final-state → empty-stack (dump everything)

WHAT. Now the reverse: given accepting by final state, build that empties its stack on the same strings.

WHY. To make emptiness mean "accept," we must clear all plates — but only after truly reaching a happy mood, and never before. Again a fresh floor protects us: 's own machine might momentarily empty its plates mid-run without being in ; the extra floor stops that from counting.

PICTURE. From any happy mood, a red cascade of -moves pops plate after plate until nothing (not even ) is left.

Construction, annotated:

  • New floor: run above the protective floor.
  • Add dump mood . For every and every stack symbol : enters dumping, then for every (including ) — pop everything, floor and all, reaching empty stack.

Because only ever gets popped inside the dump phase (entered only from a genuine final state), the two modes accept identical strings.


The one-picture summary

WHAT. One diagram: the same PDA core, two accept sockets. Left socket lights up when the stack floor is bare (empty stack). Right socket lights up when the mood is happy (final state). The two convertibility arrows show each can be rebuilt as the other — so both recognize exactly the context-free languages.

Recall Feynman: the whole walkthrough in plain words

A robot reads letters and holds a stack of plates; it can only touch the top plate. To check as match bs, it puts a plate down for each a and lifts one off for each b. There are two ways it can announce "you passed." One: it lifts the last plate off — no plates left means the counts balanced ("empty = exhausted"). Two: it finishes in a smiley mood, plates or no plates ("final = feeling"). Do they have equal power? Yes. If your robot uses the empty-plate rule, I slip an extra floor-plate underneath; when your real plates are gone, my floor pokes out and I make the robot smile — that's the empty→final rebuild. If your robot uses the smiley rule, I let it smile first, then have it toss every plate (floor included) off the table — that's the final→empty rebuild. The extra floor-plate is the trick that stops the robot from accidentally emptying or smiling too early. Same robot, same passing strings, two ways to say "passed."



Flashcards

A configuration (ID) is which triple?
= current state, unread input, full stack with top written leftmost.
Write the one-step yields rule when .
.
In , which plate is on top?
— the top is written leftmost.
Define acceptance by empty stack.
accepted iff ; final states ignored.
Define acceptance by final state.
accepted iff with ; stack ignored.
Why add a fresh marker in conversions?
So the simulated machine never empties (or "passes") accidentally — surfaces only at the true accept moment.
Empty→final: what triggers the happy mood?
The fresh floor becoming exposed, i.e. the original stack is empty.
Final→empty: what does the dump phase do?
From a final state, -pop every plate including until the stack is truly empty.