Pushdown Automata

Lesson 16 adds one unbounded stack to a finite automaton. It explains why a stack is exactly the right addition and what its last-in-first-out discipline still forbids, then covers transitions that read, pop, and push, with each part optional, and the bottom-marker trick for testing emptiness. It gives the formal seven-tuple and the six-tuple variant, configurations and the computation relation, and the final-state and empty-stack acceptance conventions with conversions in both directions. Designs follow for matched counts, palindromes, two kinds of bracket, and strict inequalities. It closes with the result that deterministic pushdown automata are strictly weaker, giving the standard witness language and explaining why the subset construction cannot be transferred.

Subject: Theory of Computation · 116 slides · symbolic lesson

Open the interactive version of this deck · Homework for this lesson

What this lesson covers

The lesson, slide by slide

1. Pushdown Automata

Title

Theory of Computation · Lesson 16

Bolt one unbounded stack onto a finite automaton. It is exactly enough memory to match nesting — and no more.

2. What you will be able to do

Objectives

Lesson 13 gave a generator for the context-free languages. This lesson gives the recognizer. By the end you can:

  1. Explain why a stack is the right amount of extra memory, and what it still cannot do.
  2. Read a transition and say what it reads, pops and pushes.
  1. Write the formal seven-tuple, and track a computation as a sequence of configurations.
  2. State both acceptance conventions and convert between them.
  1. Design machines for matched counts, palindromes and bracket languages.
  2. Explain why the deterministic variant is strictly weaker — unlike the finite-automaton case.

3. What survived from Chomsky Normal Form?

Warm-up

Discussion prompt

Before we open Pushdown Automata: without looking back, what was the main idea of Chomsky Normal Form, and what could you do by the end of it that you could not do before?

Hint: One sentence for the idea, one for the skill. If the second one is blank, that is the part to revisit.

Answer:

Lesson 15 makes grammars uniform. Covers the two permitted rule shapes and the single start-variable exception, the derivation-length property that follows, removing useless variables with generating computed before reachable, removing epsilon-rules by adding one alternative per subset of nullable positions and why every subset is needed, removing unit rules by closing over unit pairs including cycles, lifting terminals and binarizing long rules, and the full four-pass pipeline with a justification for each ordering constraint.

4. Why a Stack

Section

Section 1

5. The gap left by finite memory

Concept

Lesson 11 pinned down exactly what finite automata lack: the ability to carry an unbounded quantity from one part of a string to a later part.

Matched counts, balanced brackets and palindromes all failed for the same reason. The machine had to remember something whose range grew with the input, and finitely many states cannot.

\[ \text{unbounded quantity to carry} \;\Rightarrow\; \text{no finite automaton} \]

So the fix is to add storage. The question is how much, and with what discipline — because unrestricted storage would overshoot and give the machines of Lesson 20 straight away.

6. Break it if you can: The gap left by finite memory

Counterexample

Discussion prompt

Matched counts, balanced brackets and palindromes all failed for the same reason. The machine had to remember something whose range grew with the input, and finitely many states cannot.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

7. A stack is the smallest useful addition

Intuition

Adding a stack gives unbounded storage with a severe restriction: only the top item is visible, and items come off in the reverse order they went on.

That restriction is exactly right for nesting. An opening bracket goes on the stack and its matching closing bracket takes it off, so the most recent unmatched opening is always the one on top.

Memory addedRecognizesToo much?
nothingregular languages—
one stackcontext-free languagesno — matches nesting exactly
two stackseverything a Turing machine canyes — overshoots
a countera proper subclassno — undershoots

8. Fill in: Recognizes for A stack is the smallest useful addition

Comparison

Comparison matrix

From A stack is the smallest useful addition: refill the Recognizes column from what you know. The rest of the table is as it appeared.

Memory addedRecognizesToo much?
nothingregular languages—
one stackcontext-free languagesno — matches nesting exactly
two stackseverything a Turing machine canyes — overshoots
a countera proper subclassno — undershoots

9. The three operations

Concept

A stack supports exactly three moves, and nothing else is available.

  1. Push a symbol onto the top.
  2. Pop the top symbol off, which requires knowing what it is.
  3. Test the top symbol, which happens as part of popping.

There is no way to look at the second item, count the items, or read the bottom without removing everything above it. Those restrictions are what keep the model from being too powerful.

\[ \text{visible} = \text{top symbol only} \]

10. By analogy: The three operations

Analogy

Discussion prompt

Explain The three operations by analogy to something with no Theory of Computation in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

A stack supports exactly three moves, and nothing else is available.

11. What has to happen first: Match brackets with a stack, by hand

Ranking

Put in order

Put the moves of Match brackets with a stack, by hand into the order they have to happen.

  1. On an opening bracket, push
  2. On a closing bracket, pop
  3. At the end, check the stack is empty
  4. Verify on three inputs

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Record that one more closing bracket is now owed.

12. Match brackets with a stack, by hand

Worked example

Before any formalism, run the algorithm you would write yourself, and notice it uses only the three operations.

Set up

Why: Start with an empty stack and read the input left to right.

On an opening bracket, push

Why: Record that one more closing bracket is now owed.

\[ ( \;\longrightarrow\; \text{push} \]

On a closing bracket, pop

Why: If the stack is empty there was nothing to match, so reject. Otherwise remove one item.

\[ ) \;\longrightarrow\; \text{pop, or reject if empty} \]

At the end, check the stack is empty

Why: Anything left means an opening bracket was never matched.

Verify on three inputs

Why: The string with two nested pairs pushes twice then pops twice, ending empty — accept. The string with a closing bracket first tries to pop an empty stack — reject. The string with one unmatched opening ends with an item still present — reject. All three verdicts match the language.

\[ (()) \in L \qquad )( ,\ (() \notin L \ \checkmark \]

13. Match brackets with a stack, by hand — line by line

Picture it

Animation

Shows: Each line of the worked example "Match brackets with a stack, by hand", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The string with two nested pairs pushes twice then pops twice, ending empty — accept. The string with a closing bracket first tries to pop an empty stack — reject. The string with one unmatched opening ends with an item still present — reject. All three verdicts match the language.

14. Why the stack must be unbounded

Concept

The stack's depth is what carries the unbounded quantity, so bounding it would collapse the model back to finite automata.

A stack of depth at most k has finitely many possible contents, so the machine's whole situation — state plus stack — takes finitely many values. That is a finite automaton with more states.

\[ \text{bounded stack} \;\Rightarrow\; \text{finitely many situations} \;\Rightarrow\; \text{regular} \]

Unboundedness is therefore not a convenience but the entire source of the extra power, exactly as unbounded nesting depth was the source of the difficulty.

15. Teach it back: Why the stack must be unbounded

Explain it

Discussion prompt

Explain Why the stack must be unbounded to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

The stack's depth is what carries the unbounded quantity, so bounding it would collapse the model back to finite automata.

16. What a stack still cannot do

Intuition

The discipline that makes a stack useful also limits it, and knowing the limit early explains Lesson 18.

Items come off in reverse order, so a stack can compare a prefix against a reversed suffix — but not against a suffix in the same order. And once popped, an item is gone, so a quantity can be checked once and not twice.

LanguageWithin reach?Why
matched countsyespush then pop once
palindromesyesreversal is what a stack gives
a block written twicenoneeds the same order, not reversed
three matched countsnothe count is consumed by the first check

17. Which is which, by Within reach?

Discrimination

Sort into buckets

Sort these by Within reach?, from memory, without looking back at What a stack still cannot do. Telling them apart on the spot is the skill; the table is only where the answer happens to be written down.

yes
matched counts; palindromes
no
a block written twice; three matched counts
g1
Within reach? is "yes" for matched counts, palindromes — that is what the table on "What a stack still cannot do" records, and it is the single property separating this group from the rest.
g2
Within reach? is "no" for a block written twice, three matched counts — that is what the table on "What a stack still cannot do" records, and it is the single property separating this group from the rest.

18. Rebuild the recipe: Deciding whether a stack suffices

Ranking

Put in order

These are the steps of Deciding whether a stack suffices, scrambled. Put them back in order before the next slide shows you.

  1. Identify the quantity that must be carried from early in the string to later.
  2. Ask whether it is consumed exactly once — a stack cannot check the same count twice.
  3. Ask whether the comparison is against a reversal, or against the same order.
  4. If the answer is once and reversed, a stack works.
  5. If a count must be matched twice, or an order preserved, expect Lesson 18 to rule it out.

Why: This is the order the recipe itself gives. Recalling the sequence without the slide in front of you is the difference between recognising the method and being able to run it — most of what goes wrong in practice is a step done out of turn.

19. Deciding whether a stack suffices

Pattern

Before designing a machine, ask whether the language's structure fits a stack's discipline.

  1. Identify the quantity that must be carried from early in the string to later.
  2. Ask whether it is consumed exactly once — a stack cannot check the same count twice.
  3. Ask whether the comparison is against a reversal, or against the same order.
  4. If the answer is once and reversed, a stack works.
  5. If a count must be matched twice, or an order preserved, expect Lesson 18 to rule it out.

The fourth line covers every design in this lesson. The fifth covers the standard non-context-free examples.

20. Rule out three: Check yourself: what a stack buys

Elimination

Eliminate the wrong options

Why can a pushdown automaton recognize palindromes but not strings consisting of a block written twice?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. A stack returns items reversed, which matches a palindrome but not a repetition
  • B. Palindromes are a finite language
  • C. A repeated block requires an unbounded stack and a palindrome does not
  • D. Palindromes are regular

Survives elimination: A

Why: Pushing the first half and popping while reading the second compares the second half against the reverse of the first — exactly the palindrome condition. A repeated block needs the second half compared in the same order, and a stack cannot produce that.

21. Check yourself: what a stack buys

Check

Think about the order items come off.

Check your understanding

Why can a pushdown automaton recognize palindromes but not strings consisting of a block written twice?

  • A. A stack returns items reversed, which matches a palindrome but not a repetition (correct)
  • B. Palindromes are a finite language
  • C. A repeated block requires an unbounded stack and a palindrome does not
  • D. Palindromes are regular

Answer: A

Why: Pushing the first half and popping while reading the second compares the second half against the reverse of the first — exactly the palindrome condition. A repeated block needs the second half compared in the same order, and a stack cannot produce that.

Why B tempts people
Palindromes over a two-symbol alphabet form an infinite language, and Lesson 11 proved it is not even regular.
Why C tempts people
Both need unbounded storage. The difference is the order in which the stored symbols come back out.
Why D tempts people
Lesson 11 proved the palindromes are not regular, which is precisely why a stack was needed.

22. The stack is the parse in progress

Intuition

There is a deeper reading of what the stack holds, and Lesson 17 makes it precise.

When a machine is built from a grammar, the stack holds the part of the derivation not yet matched against the input — the pending obligations. Popping a symbol discharges one obligation.

So the stack is not an ad-hoc memory: it is the frontier of a partially built parse tree. That is why exactly this discipline matches exactly this class of grammars.

\[ \text{stack contents} \;\longleftrightarrow\; \text{unmatched part of the derivation} \]

23. The Machine, Informally

Section

Section 2

24. What a transition does

Concept

A single move of the machine involves three things at once, and every one of them is optional in a specific sense.

  1. Read one input symbol, or read nothing.
  2. Pop one stack symbol, or pop nothing.
  3. Push a string of stack symbols, possibly empty.

A transition is written with the input, the popped symbol and the pushed string, separated by commas and an arrow.

\[ a, X \to \gamma \]

Read that as: on input a, with X on top of the stack, remove X and put the string in its place.

25. The three optional parts

Concept

Each of the three components may be the empty string, and each choice means something specific.

WrittenMeans
a symbol as inputconsume that symbol
empty inputmove without consuming — a free move
a symbol as poprequire it on top, and remove it
empty popdo not inspect or remove anything
a symbol as pushput it on top
empty pushput nothing back — a net pop

Pushing two symbols where one was popped grows the stack by one; pushing the same symbol back leaves the depth unchanged.

26. What each one costs: The three optional parts

Trade off

Comparison matrix

From The three optional parts: every row here is a choice with a cost. Fill the Means column, then say which row you would actually pick and what you give up for it.

WrittenMeans
a symbol as inputconsume that symbol
empty inputmove without consuming — a free move
a symbol as poprequire it on top, and remove it
empty popdo not inspect or remove anything
a symbol as pushput it on top
empty pushput nothing back — a net pop

27. Plan first: Read three transitions

Step zero

Discussion prompt

Read three transitions — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: A pure push

Answer:

  1. A pure push
  2. A pure pop
  3. A test that leaves the stack alone
  4. Note the third is how emptiness is tested
  5. Verify the depth changes are as stated

28. Read three transitions

Worked example

Translate the notation into plain English, since every design that follows is written this way.

A pure push

Why: Read an a, do not inspect the stack, and put an X on top. The stack grows by one.

\[ a, \varepsilon \to X \]

A pure pop

Why: Read a b, require an X on top, and put nothing back. The stack shrinks by one.

\[ b, X \to \varepsilon \]

A test that leaves the stack alone

Why: Read nothing, require the bottom marker on top, and put it straight back. This checks the stack is otherwise empty without disturbing it.

\[ \varepsilon, Z \to Z \]

Note the third is how emptiness is tested

Why: A stack cannot be asked whether it is empty. The standard trick is to push a marker at the start and test for it, which is what the seven-tuple's initial stack symbol is for.

Verify the depth changes are as stated

Why: The first adds one symbol and removes none, the second removes one and adds none, and the third removes one and adds one. Net changes of plus one, minus one and zero — matching the descriptions.

\[ +1, \; -1, \; 0 \ \checkmark \]

29. Read three transitions — line by line

Picture it

Animation

Shows: Each line of the worked example "Read three transitions", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The first adds one symbol and removes none, the second removes one and adds none, and the third removes one and adds one. Net changes of plus one, minus one and zero — matching the descriptions.

30. The stack profile of a computation

Concept

Plotting the stack depth against the input position is a fast way to understand what a machine is doing.

Shape of the profileWhat the machine is doing
rises then falls oncestore a prefix, match it against a suffix
rises and falls repeatedlymatch nested structure as it goes
stays near zerothe stack is barely used — probably a regular language
rises without fallingnothing is ever checked — the design is incomplete

The last row is a genuine bug signal. A machine that pushes and never pops is not using its stack to decide anything, so its language is regular whatever the design intended.

31. Guess the shape of the answer: Read a language off a stack profile

Estimation

Predict first

Practise the diagnostic on a machine described only by what it does to the stack.

Commit before you compute: what does Read a language off a stack profile come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify the inference on three strings

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. The string acb has one of each and empties the stack; aaccbb has an extra c and has no applicable transition at the second c; ab has no c at all and never leaves the first phase.

32. Read a language off a stack profile

Worked example

Practise the diagnostic on a machine described only by what it does to the stack.

Take the description

Why: The machine pushes one marker per symbol while reading a's, does nothing to the stack while reading a single c, then pops one marker per symbol while reading b's.

Read the profile

Why: The depth rises through the first block, is flat for one symbol, then falls through the last block — a single rise and fall.

Infer the condition

Why: The number of pops must match the number of pushes for the stack to empty, so the two blocks have equal length, with the middle symbol as a marker.

\[ L = \{\, a^{n}cb^{n} : n \ge 0 \,\} \]

Check the marker's role

Why: The single c makes the phase boundary visible in the input, so no guessing is needed and the machine is deterministic.

Verify the inference on three strings

Why: The string acb has one of each and empties the stack; aaccbb has an extra c and has no applicable transition at the second c; ab has no c at all and never leaves the first phase. Only the first is accepted, matching the inferred language.

\[ acb,\ aacbb \in L \qquad aaccbb,\ ab \notin L \ \checkmark \]

33. Read a language off a stack profile — line by line

Picture it

Animation

Shows: Each line of the worked example "Read a language off a stack profile", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The single c makes the phase boundary visible in the input, so no guessing is needed and the machine is deterministic.

34. Nondeterminism is built in

Concept

These machines are nondeterministic by default, in exactly the sense of Lesson 5, and for the same reasons.

A configuration may have several applicable transitions, or none. Acceptance requires some computation to succeed, and a stuck branch proves nothing.

\[ \text{accept} \iff \exists \text{ an accepting computation} \]

Free moves are available too, so the machine may reorganize its stack without consuming input. Both features are used constantly in the designs of Section 5.

35. What has to be given first: Trace a machine on a matched-count string

Missing information

Discussion prompt

Run the standard machine for matched counts, tracking state, remaining input and stack together.

What do you need to know — or decide — before the first line can be written? List everything the problem has to hand you.

Hint: Anything you would have to invent to get started is a thing the problem must supply.

Answer:

State one, the whole input still to read, and an empty stack apart from the bottom marker.

36. Trace a machine on a matched-count string

Worked example

Run the standard machine for matched counts, tracking state, remaining input and stack together.

\[ q_1: \; a, \varepsilon \to X \qquad q_2: \; b, X \to \varepsilon \]

Start

Why: State one, the whole input still to read, and an empty stack apart from the bottom marker.

\[ (q_1, \; aabb, \; Z) \]

Push for each a

Why: Two a's are read, pushing one marker each. The stack now records how many b's are owed.

\[ (q_1, \; bb, \; XXZ) \]

Switch to popping

Why: A free move takes the machine to the second state, where b's are matched against the stack.

\[ (q_2, \; bb, \; XXZ) \]

Pop for each b

Why: Two b's are read, each requiring and removing one marker. The stack returns to just the bottom marker.

\[ (q_2, \; \varepsilon, \; Z) \]

Verify acceptance and check a rejected string

Why: The input is exhausted with only the marker left, so the counts matched and the string is accepted. Running aab instead leaves one marker on the stack with no input remaining, so no accepting computation exists — correctly rejecting it.

\[ aabb \in L \qquad aab,\ abb \notin L \ \checkmark \]

37. Trace a machine on a matched-count string — line by line

Picture it

Animation

Shows: Each line of the worked example "Trace a machine on a matched-count string", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The input is exhausted with only the marker left, so the counts matched and the string is accepted. Running aab instead leaves one marker on the stack with no input remaining, so no accepting computation exists — correctly rejecting it.

38. Something is wrong here: assuming the stack can be tested for emptiness

Anomaly

Predict first

A student writes this, and it looks reasonable:

Design a machine that accepts only when the stack has been fully emptied.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: Write a move that fires when nothing is on the stack, and let it enter the accepting state.

Design a machine that accepts only when the stack has been fully emptied.

Why: Write a move that fires when nothing is on the stack, and let it enter the accepting state.

39. Trap: assuming the stack can be tested for emptiness

Trap

The trap

Design a machine that accepts only when the stack has been fully emptied.

Add a transition conditioned on an empty stack

Why: Write a move that fires when nothing is on the stack, and let it enter the accepting state.

\[ \varepsilon, \text{empty} \to \varepsilon \]

Notice the notation cannot express it

Why: Every transition's pop component names a symbol to require, or names nothing at all. There is no symbol meaning 'the stack is empty', and a transition that pops nothing fires regardless of the contents.

The fix

Design a machine that accepts only when the stack has been fully emptied.

Push a bottom marker before anything else

Why: The very first move, consuming no input, pushes a symbol used nowhere else.

\[ \varepsilon, \varepsilon \to Z \]

Test for the marker instead of for emptiness

Why: Seeing the marker on top means everything pushed above it has been popped, which is the condition that was wanted.

\[ \varepsilon, Z \to \varepsilon \]

Note this is what the seven-tuple formalizes

Why: The initial stack symbol in the formal definition is exactly this marker, provided by the definition rather than pushed by hand.

\[ Z_0 \in \Gamma \ \checkmark \]

40. Decode the notation: Trap: assuming the stack can be tested for emptiness

Notation

Annotate

From Trap: assuming the stack can be tested for emptiness — read this one piece at a time. What is each part doing?

On: \( \varepsilon, \text{empty} \to \varepsilon \)

  • Write a move that fires when nothing is on the stack, and let it enter the accepting state.
  • Every transition's pop component names a symbol to require, or names nothing at all. There is no symbol meaning 'the stack is empty', and a transition that pops nothing fires regardless of the contents.
  • The very first move, consuming no input, pushes a symbol used nowhere else.

41. Reading a machine's transitions

Pattern

Given an unfamiliar machine, this recovers what it does.

  1. Group the transitions by state, and name each state by what phase it represents.
  2. For each transition, note the net effect on the stack depth: plus one, minus one, or zero.
  3. Find the transitions that consume no input — they are the phase changes.
  4. Find the transitions that test the bottom marker — they are the end-of-computation checks.
  5. Trace the shortest member of the intended language before generalizing.

The second step is the most informative. A machine's stack profile — where it grows and where it shrinks — usually reveals the language immediately.

42. The Formal Definition

Section

Section 3

43. The seven-tuple

Concept

Two more components than a finite automaton: an alphabet for the stack, and a symbol to start it with.

\[ P = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F) \]

ComponentWhat it is
Qa finite set of states
the input alphabetsymbols the machine reads
the stack alphabetsymbols the machine may push
the transition functiondescribed on the next slide
the start stateone element of Q
the initial stack symbolone element of the stack alphabet
Fthe accepting states

The two alphabets are usually different and need not overlap. The stack alphabet often contains markers that never appear in any input.

44. Fill in: What it is for The seven-tuple

Comparison

Comparison matrix

From The seven-tuple: refill the What it is column from what you know. The rest of the table is as it appeared.

ComponentWhat it is
Qa finite set of states
the input alphabetsymbols the machine reads
the stack alphabetsymbols the machine may push
the transition functiondescribed on the next slide
the start stateone element of Q
the initial stack symbolone element of the stack alphabet
Fthe accepting states

45. The transition function

Concept

It takes a state, an input symbol or nothing, and a stack symbol, and returns a set of next moves — each a state paired with a string to push.

\[ \delta : Q \times \Sigma_{\varepsilon} \times \Gamma_{\varepsilon} \to \mathcal{P}\big(Q \times \Gamma^{*}\big) \]

Returning a set is the nondeterminism, exactly as in Lesson 5. The subscripted alphabets are the ones extended with the empty string, allowing free moves and stack-blind moves.

The pushed component is a string, so one move may push several symbols at once. That is what lets a grammar rule with a long right-hand side be applied in a single step.

46. Plan first: Write the seven-tuple for a machine

Step zero

Discussion prompt

Write the seven-tuple for a machine — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: List the states

Answer:

  1. List the states
  2. List the two alphabets
  3. Write the transition entries
  4. Name the start state, initial stack symbol and accepting set
  5. Verify the tuple reproduces the traced computation

47. Write the seven-tuple for a machine

Worked example

Formalize the matched-count machine traced earlier.

\[ q_1: \; a, \varepsilon \to X \qquad q_1 \to q_2 \text{ freely} \qquad q_2: \; b, X \to \varepsilon \]

List the states

Why: One for the pushing phase, one for the popping phase, and one accepting state reached after the marker check.

\[ Q = \{q_1, q_2, q_3\} \]

List the two alphabets

Why: The input alphabet holds the two letters; the stack alphabet holds the counting marker and the bottom marker.

\[ \Sigma = \{a,b\}, \qquad \Gamma = \{X, Z\} \]

Write the transition entries

Why: Four entries: push on a, switch phase freely, pop on b, and check the bottom marker freely.

\[ \delta(q_1,a,\varepsilon) = \{(q_1, X)\}, \quad \delta(q_2,b,X) = \{(q_2,\varepsilon)\} \]

Name the start state, initial stack symbol and accepting set

Why: Start in the pushing phase with the bottom marker on the stack; accept in the third state.

\[ q_0 = q_1, \quad Z_0 = Z, \quad F = \{q_3\} \]

Verify the tuple reproduces the traced computation

Why: Running the tuple on the four-symbol string gives the same four configurations traced in Section 2, ending in the accepting state with only the bottom marker present. Nothing was lost in the formalization.

\[ aabb \in L(P) \ \checkmark \]

48. Write the seven-tuple for a machine — line by line

Picture it

Animation

Shows: Each line of the worked example "Write the seven-tuple for a machine", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Running the tuple on the four-symbol string gives the same four configurations traced in Section 2, ending in the accepting state with only the bottom marker present. Nothing was lost in the formalization.

49. The six-tuple variant

Concept

Some texts drop the initial stack symbol and start with an empty stack. Both conventions are in wide use and neither is more powerful.

ConventionComponentsEmptiness test
seven-tupleincludes an initial stack symboltest for that symbol
six-tuplestarts with an empty stackpush your own marker first

Converting between them is one transition: a six-tuple machine gains a first move pushing a marker, and a seven-tuple machine can ignore its initial symbol. This deck uses the seven-tuple, and flags where the choice matters.

\[ \varepsilon, \varepsilon \to Z_0 \quad\text{— the bridging move} \]

50. Answer it before you see the options: Check yourself: the formal definition

Prediction

Predict first

Why does the transition function of a pushdown automaton return a string to push rather than a single symbol?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: So one move can push several symbols, matching a grammar rule with a long right-hand side

Why: Lesson 17 builds a machine from a grammar by pushing a rule's entire right-hand side in one move. Allowing a string keeps that construction to one transition per rule rather than a chain of them.

51. Check yourself: the formal definition

Check

Look at what the transition function returns.

Check your understanding

Why does the transition function of a pushdown automaton return a string to push rather than a single symbol?

  • A. So one move can push several symbols, matching a grammar rule with a long right-hand side (correct)
  • B. Because the stack alphabet is infinite
  • C. Because popping requires pushing the same number of symbols back
  • D. To allow the machine to read several input symbols at once

Answer: A

Why: Lesson 17 builds a machine from a grammar by pushing a rule's entire right-hand side in one move. Allowing a string keeps that construction to one transition per rule rather than a chain of them.

Why B tempts people
The stack alphabet is finite, exactly like the input alphabet. Only the stack's depth is unbounded.
Why C tempts people
Nothing requires the depth to be preserved — pure pushes and pure pops are both ordinary moves.
Why D tempts people
The input component is a single symbol or nothing. Reading several symbols at once is never permitted.

52. Configurations

Concept

configuration — A snapshot of the whole machine: its current state, the input still to be read, and the entire stack contents.

\[ (q, \; w, \; \gamma) \]

The stack is written top-first by convention, so the leftmost symbol is the one a pop would remove. Getting this orientation backwards is the commonest source of confusion in traces.

A configuration is to these machines what a state was to finite automata: everything the machine knows. The difference is that there are now infinitely many possible configurations.

53. Step between configurations

Worked example

Apply a transition formally, as a relation on configurations.

\[ (q, \; aw, \; X\gamma) \;\vdash\; (p, \; w, \; \beta\gamma) \]

Read the left side

Why: The machine is in some state, the next input symbol is a, and the top of the stack is X with the rest below.

Find an applicable transition

Why: A move is applicable when its input component matches the next symbol or is empty, and its pop component matches the top symbol or is empty.

Apply it

Why: The state changes, the matched input symbol is consumed, the popped symbol is removed, and the pushed string takes its place — leaving everything below untouched.

Note what is unchanged

Why: The part of the stack below the popped symbol is carried through verbatim. That is the formal statement of 'only the top is visible'.

Verify on a concrete step

Why: From the pushing state with input aabb and stack Z, the push transition consumes one a and puts X above Z, giving the state with input abb and stack XZ. The tail Z was carried through untouched, exactly as the relation describes.

\[ (q_1, aabb, Z) \vdash (q_1, abb, XZ) \ \checkmark \]

54. Step between configurations — line by line

Picture it

Animation

Shows: Each line of the worked example "Step between configurations", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: From the pushing state with input aabb and stack Z, the push transition consumes one a and puts X above Z, giving the state with input abb and stack XZ. The tail Z was carried through untouched, exactly as the relation describes.

55. The computation relation

Concept

Chain single steps to get whole computations, using the reflexive transitive closure exactly as in Lesson 13.

\[ (q_0, \; w, \; Z_0) \;\vdash^{*}\; (q, \; \varepsilon, \; \gamma) \]

A computation is accepting when it consumes the whole input and finishes in a configuration the acceptance convention approves of. The two conventions are the subject of the next section.

Because the machine is nondeterministic, a single input generally has many computations. Only one need be accepting.

56. Acceptance, Two Ways

Section

Section 4

57. Accepting by final state

Concept

The first convention is the familiar one: consume the input and finish in a state belonging to the accepting set.

\[ w \in L(P) \iff (q_0, w, Z_0) \vdash^{*} (q, \varepsilon, \gamma) \text{ for some } q \in F \]

The stack contents at the end are irrelevant under this convention. Whatever is left over is simply ignored.

This matches the finite-automaton convention and is what the seven-tuple's accepting set is for.

58. Accepting by empty stack

Concept

The second convention ignores the state instead: consume the whole input and finish with nothing on the stack.

\[ w \in N(P) \iff (q_0, w, Z_0) \vdash^{*} (q, \varepsilon, \varepsilon) \]

Under this convention the accepting set plays no role at all, and machines are often written as six-tuples with it omitted.

The two conventions recognize exactly the same class of languages, but a given machine usually accepts different languages under each.

59. Guess the shape of the answer: Convert between the two conventions

Estimation

Predict first

Show the conventions are interchangeable, which is why textbooks may pick either.

Commit before you compute: what does Convert between the two conventions come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify both directions preserve the language

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. In the first, an accepting computation ends exactly when the original emptied its stack; in the second, exactly when the original reached an accepting state.

60. Convert between the two conventions

Worked example

Show the conventions are interchangeable, which is why textbooks may pick either.

From empty stack to final state

Why: Push a fresh bottom marker below everything, using a new start state. Then a free move that pops the marker enters a new accepting state.

\[ \varepsilon, Z_{\text{new}} \to \varepsilon \;\text{ into the accepting state} \]

See why the fresh marker is needed

Why: Without it, the machine could not tell an empty stack from one still holding symbols, since emptiness cannot be tested directly.

From final state to empty stack

Why: Add a draining state reachable freely from every accepting state, which pops any symbol and consumes no input until the stack is bare.

\[ \varepsilon, X \to \varepsilon \;\text{ for every } X \in \Gamma \]

See why a fresh bottom marker is needed here too

Why: Without one, the draining state could empty the stack from a non-accepting configuration and wrongly accept. The marker ensures only the intended computations reach an empty stack.

Verify both directions preserve the language

Why: In the first, an accepting computation ends exactly when the original emptied its stack; in the second, exactly when the original reached an accepting state. Neither adds nor removes strings, so the two conventions define the same class.

\[ \{L(P)\} = \{N(P')\} \ \checkmark \]

61. Convert between the two conventions — line by line

Picture it

Animation

Shows: Each line of the worked example "Convert between the two conventions", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: In the first, an accepting computation ends exactly when the original emptied its stack; in the second, exactly when the original reached an accepting state. Neither adds nor removes strings, so the two conventions define the same class.

62. Something is wrong here: assuming one machine accepts the same language both…

Anomaly

Predict first

A student writes this, and it looks reasonable:

A machine accepts the matched counts by final state. What does it accept by empty stack?

It is wrong. Say what breaks — and say it before you turn the page.

Correct: The two conventions define the same class of languages, so the same machine must accept the same language under either.

A machine accepts the matched counts by final state. What does it accept by empty stack?

Why: The two conventions define the same class of languages, so the same machine must accept the same language under either.

63. Trap: assuming one machine accepts the same language both ways

Trap

The trap

A machine accepts the matched counts by final state. What does it accept by empty stack?

Assume the conventions agree

Why: The two conventions define the same class of languages, so the same machine must accept the same language under either.

\[ L(P) \overset{?}{=} N(P) \]

Test the assumption

Why: The machine leaves its bottom marker on the stack when it accepts, so its stack is never empty. Under the empty-stack convention it accepts nothing at all.

\[ N(P) = \varnothing \]

The fix

A machine accepts the matched counts by final state. What does it accept by empty stack?

Distinguish the class from the machine

Why: The conventions define the same class of languages: for every machine under one convention there is some machine under the other. That is a statement about existence, not about the same machine.

\[ \{L(P) : P\} = \{N(P) : P\} \]

Convert explicitly if the same language is wanted

Why: Apply the construction from the previous slides, which builds a different machine accepting the same language under the other convention.

\[ L(P) = N(P') \;\text{ for the constructed } P' \ \checkmark \]

64. Which of these survive contact with Pushdown Automata?

Two truths and a lie

Sort into buckets

Some of these hold up and some are the exact mistakes this lesson is built to prevent. Sort them.

Holds up
Adding a stack gives unbounded storage with a severe restriction: only the top item is visible, and items come off in the reverse order they went on.; A stack supports exactly three moves, and nothing else is available.; The stack's depth is what carries the unbounded quantity, so bounding it would collapse the model back to finite automata.
Breaks
Design a machine that accepts only when the stack has been fully emptied.; A machine accepts the matched counts by final state. What does it accept by empty stack?
sound
These are stated as this lesson states them — each one survives the edge cases Pushdown Automata puts it through.
flawed
Each of these is lifted from a trap in this deck: reasonable-sounding, and wrong in a way that only shows up once you rely on it.

65. What has to happen first: Trace an accepting and a rejecting computation

Ranking

Put in order

Put the moves of Trace an accepting and a rejecting computation into the order they have to happen.

  1. Describe the machine
  2. Trace an accepting branch on abba
  3. Note the branches that fail
  4. Trace the rejecting input abab
  5. Verify the verdicts

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Push each symbol read; at some point guess the midpoint and switch phases freely; then pop, requiring each input symbol to match the symbol popped.

66. Trace an accepting and a rejecting computation

Worked example

Run the palindrome machine on two inputs, to see nondeterminism at work.

\[ \text{push phase} \;\to\; \text{free switch} \;\to\; \text{match phase} \]

Describe the machine

Why: Push each symbol read; at some point guess the midpoint and switch phases freely; then pop, requiring each input symbol to match the symbol popped.

Trace an accepting branch on abba

Why: Push a and b, switch after two symbols, then pop b against b and a against a. The stack returns to the marker with the input exhausted.

\[ (q_1, abba, Z) \vdash^{*} (q_2, ba, baZ) \vdash^{*} (q_2, \varepsilon, Z) \]

Note the branches that fail

Why: Switching after one symbol or three symbols leads to a mismatch, and those branches die. Acceptance needs only the one branch that guessed correctly.

Trace the rejecting input abab

Why: Every possible midpoint guess leads to a mismatch, since the string does not read the same backwards.

Verify the verdicts

Why: The first input has an accepting computation and is accepted; the second has none, since every guess fails, and is rejected. Both match the palindrome condition, and the machine needed nondeterminism to find the midpoint.

\[ abba \in L \qquad abab \notin L \ \checkmark \]

67. Trace an accepting and a rejecting computation — line by line

Picture it

Animation

Shows: Each line of the worked example "Trace an accepting and a rejecting computation", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The first input has an accepting computation and is accepted; the second has none, since every guess fails, and is rejected. Both match the palindrome condition, and the machine needed nondeterminism to find the midpoint.

68. Without one step: Tracing a computation reliably

Constraint

Discussion prompt

Run Tracing a computation reliably with this step confiscated:

Consume exactly one input symbol per step, or none for a free move.

Is it still possible? If it is, say what takes its place and what it costs you. If it is not, say exactly what that step was providing that nothing else does.

Hint: A step you can drop for free was never load-bearing. If you cannot drop it, name the thing that goes wrong the moment it is gone.

Answer:

  1. Write each configuration as a triple, always in the same order.
  2. Write the stack top-first, and keep that orientation throughout.
  3. Consume exactly one input symbol per step, or none for a free move.
  4. Show the whole stack every time, not just the change.
  5. When several transitions apply, follow the branch you expect to succeed, and note the others exist.

69. Tracing a computation reliably

Pattern

Configurations have three components and it is easy to lose track of one.

  1. Write each configuration as a triple, always in the same order.
  2. Write the stack top-first, and keep that orientation throughout.
  3. Consume exactly one input symbol per step, or none for a free move.
  4. Show the whole stack every time, not just the change.
  5. When several transitions apply, follow the branch you expect to succeed, and note the others exist.

The fourth habit is worth the extra writing. Most trace errors are a symbol silently dropped from the middle of the stack.

70. Where does it stop working: Tracing a computation reliably

Edge cases

Discussion prompt

Tracing a computation reliably works on the cases you have just seen. Push it to the edge: what is the most degenerate input it still handles — empty, zero, one item, everything equal — and what is the first case where it stops being true? Name the case, not just "it breaks".

Hint: Try the smallest legal input, then the largest, then the one where two things collide. Methods are specified at their edges; the middle takes care of itself.

Answer:

Configurations have three components and it is easy to lose track of one.

71. How sure are you: Check yourself: acceptance

Commit first

Predict first

Under the final-state convention, what must be true of the stack when a string is accepted?

Commit to an answer, then rate it — certain, fairly sure, or guessing — and write the rating down before you turn the page.

Correct: Nothing — the stack contents are ignored

Why: The final-state convention examines only the state reached after the input is exhausted. Whatever remains on the stack plays no part in the decision, which is exactly what distinguishes it from the empty-stack convention.

The rating matters as much as the answer: confident-and-wrong is the combination that survives revision, because nothing about it feels like it needs revisiting.

72. Check yourself: acceptance

Check

Recall what each convention examines at the end.

Check your understanding

Under the final-state convention, what must be true of the stack when a string is accepted?

  • A. Nothing — the stack contents are ignored (correct)
  • B. It must be empty
  • C. It must contain only the initial stack symbol
  • D. It must contain at least one symbol

Answer: A

Why: The final-state convention examines only the state reached after the input is exhausted. Whatever remains on the stack plays no part in the decision, which is exactly what distinguishes it from the empty-stack convention.

Why B tempts people
That is the empty-stack convention. Requiring both would be a third, more restrictive convention that is not standard.
Why C tempts people
Many machines do happen to end this way, but nothing in the definition requires it.
Why D tempts people
The stack may be empty, full, or anything in between. The convention simply does not look.

73. Designing Machines

Section

Section 5

74. The design recipe

Pattern

Designing a stack machine is answering two questions rather than one.

  1. What must be stored, and in what order will it be needed back?
  2. What are the phases — where does the machine switch from storing to checking?
  3. Choose stack symbols recording exactly what must be checked later.
  4. Use free moves for the phase changes, guessing where they fall.
  5. Test the bottom marker at the end, and check the empty string separately.

The second question is the new one. Finite-automaton design had a single phase; almost every stack machine has at least two, and the boundary between them is guessed.

75. State the rule before it runs: Design: matched counts

Hypothesis

Predict first

Design: matched counts is about to be worked. State your hypothesis first: which rule or definition decides this one, and what is the first move it forces? Then watch whether the example agrees with you.

Correct: Answer the storage question

Why: Store one marker per a. They come back in reverse order, which is fine because all markers are identical.

A hypothesis you wrote down is falsifiable; a vague sense of how it will go is not. If the example opens somewhere else, that gap is the thing worth chasing.

76. Design: matched counts

Worked example

The canonical design, built by the recipe.

\[ L = \{\, a^{n}b^{n} : n \ge 0 \,\} \]

Answer the storage question

Why: Store one marker per a. They come back in reverse order, which is fine because all markers are identical.

Answer the phase question

Why: Two phases: pushing while reading a's, popping while reading b's. The switch happens exactly once, at the boundary.

Write the transitions

Why: Push on a in the first phase, switch freely, pop on b in the second, and check the marker at the end.

\[ a,\varepsilon \to X; \quad \varepsilon,\varepsilon \to \varepsilon; \quad b,X \to \varepsilon; \quad \varepsilon,Z \to \varepsilon \]

Check the empty string

Why: Switching phases immediately and testing the marker accepts the empty string, which has zero of each and belongs to the language.

Verify on three strings

Why: The empty string and aabb are accepted; aab leaves a marker unpopped and abb runs out of markers, so both are rejected. All three match the language.

\[ \varepsilon,\ aabb \in L \qquad aab,\ abb \notin L \ \checkmark \]

77. Design: matched counts — line by line

Picture it

Animation

Shows: Each line of the worked example "Design: matched counts", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Switching phases immediately and testing the marker accepts the empty string, which has zero of each and belongs to the language.

78. Plan first: Design: palindromes over two symbols

Step zero

Discussion prompt

Design: palindromes over two symbols — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Answer the storage question

Answer:

  1. Answer the storage question
  2. Answer the phase question
  3. Handle both parities
  4. Write the matching phase
  5. Verify on both parities and a non-member

79. Design: palindromes over two symbols

Worked example

Here the stored symbols matter, not just their count.

\[ L = \{\, w : w = w^{R} \,\} \]

Answer the storage question

Why: Store each symbol read, so the first half can be compared against the second. Reversal is automatic.

Answer the phase question

Why: The midpoint is not marked in the input, so it must be guessed with a free move — which is why nondeterminism is essential here.

Handle both parities

Why: Even-length palindromes switch phases directly; odd-length ones must additionally consume the single middle symbol without pushing it.

\[ \varepsilon,\varepsilon \to \varepsilon \quad\text{and}\quad a,\varepsilon \to \varepsilon \;\text{ at the switch} \]

Write the matching phase

Why: For each symbol, a transition requiring the same symbol on top and popping it.

\[ a,a \to \varepsilon; \quad b,b \to \varepsilon \]

Verify on both parities and a non-member

Why: The even palindrome abba is accepted by guessing the midpoint after two symbols; the odd palindrome aba is accepted by consuming the middle b at the switch. The string ab has no successful guess, so it is rejected.

\[ abba,\ aba,\ \varepsilon \in L \qquad ab \notin L \ \checkmark \]

80. Design: palindromes over two symbols — line by line

Picture it

Animation

Shows: Each line of the worked example "Design: palindromes over two symbols", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The even palindrome abba is accepted by guessing the midpoint after two symbols; the odd palindrome aba is accepted by consuming the middle b at the switch. The string ab has no successful guess, so it is rejected.

81. What has to be given first: Design: balanced brackets of two kinds

Missing information

Discussion prompt

Now the stack symbols must record which bracket is owed.

What do you need to know — or decide — before the first line can be written? List everything the problem has to hand you.

Hint: Anything you would have to invent to get started is a thing the problem must supply.

Answer:

One symbol per bracket kind, so a pop can check that the closing bracket matches the opening it is closing.

82. Design: balanced brackets of two kinds

Worked example

Now the stack symbols must record which bracket is owed.

\[ L = \text{properly nested strings over two bracket kinds} \]

Choose the stack alphabet

Why: One symbol per bracket kind, so a pop can check that the closing bracket matches the opening it is closing.

\[ \Gamma = \{X_{(}, X_{[}, Z\} \]

Push on every opening bracket

Why: The symbol pushed records which kind was opened.

Pop on every closing bracket, requiring a match

Why: A round closing bracket pops only the round marker, and likewise for square. A mismatch has no applicable transition, so that branch dies.

\[ ) , X_{(} \to \varepsilon; \quad ] , X_{[} \to \varepsilon \]

Note that only one phase is needed

Why: Unlike the previous designs, pushing and popping interleave freely, so no phase change and no guessing are required. This machine is deterministic.

Verify on a nested, an interleaved and a mismatched string

Why: The nested string with a square pair inside a round pair is accepted, and so is the sequence of two separate pairs. The string closing a round bracket with a square one has no applicable transition and is rejected.

\[ ([]) ,\ ()[] \in L \qquad (] \notin L \ \checkmark \]

83. Design: balanced brackets of two kinds — line by line

Picture it

Animation

Shows: Each line of the worked example "Design: balanced brackets of two kinds", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The nested string with a square pair inside a round pair is accepted, and so is the sequence of two separate pairs. The string closing a round bracket with a square one has no applicable transition and is rejected.

84. Where nondeterminism is genuinely needed

Intuition

Three designs, and only two of them needed to guess. The difference is worth naming.

LanguageGuess needed?Why
balanced bracketsnoeach symbol says whether to push or pop
matched countsno, in practicethe first b marks the switch
palindromesyesthe midpoint is invisible in the input
a union of two languagesyeswhich branch to take is not determined

The rule of thumb: guessing is needed when the input contains no marker for a decision the machine must make. That is exactly the situation Section 6 shows a deterministic machine cannot handle.

85. What each one costs: Where nondeterminism is genuinely needed

Trade off

Comparison matrix

From Where nondeterminism is genuinely needed: every row here is a choice with a cost. Fill the Why column, then say which row you would actually pick and what you give up for it.

LanguageGuess needed?Why
balanced bracketsnoeach symbol says whether to push or pop
matched countsno, in practicethe first b marks the switch
palindromesyesthe midpoint is invisible in the input
a union of two languagesyeswhich branch to take is not determined

86. Guess the shape of the answer: Design: more a's than b's

Estimation

Predict first

A counting condition that is an inequality rather than an equality.

Commit before you compute: what does Design: more a's than b's come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify on three strings

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. The string a has one surplus a and is accepted; aab has one surplus and is accepted; ab cancels to nothing and is rejected, as is the empty string.

87. Design: more a's than b's

Worked example

A counting condition that is an inequality rather than an equality.

\[ L = \{\, w \in \{a,b\}^{*} : \#_a(w) > \#_b(w) \,\} \]

Decide what to store

Why: Store the running excess. Push a marker for each unmatched a, and pop one for each b that cancels an a.

Handle a b with no a to cancel

Why: The excess can go negative, so push a second kind of marker recording surplus b's. The stack then holds markers of one kind only, whichever is currently in surplus.

\[ \Gamma = \{A, B, Z\} \]

Write the cancelling transitions

Why: Reading an a pops a surplus-b marker if one is on top, and otherwise pushes a surplus-a marker. Reading a b does the mirror image.

Choose the acceptance condition

Why: Accept when the input is exhausted and at least one surplus-a marker is on top, which means the a's strictly outnumber the b's.

\[ \varepsilon, A \to A \;\text{ into the accepting state} \]

Verify on three strings

Why: The string a has one surplus a and is accepted; aab has one surplus and is accepted; ab cancels to nothing and is rejected, as is the empty string. All four match the strict inequality.

\[ a,\ aab \in L \qquad ab,\ \varepsilon \notin L \ \checkmark \]

88. Design: more a's than b's — line by line

Picture it

Animation

Shows: Each line of the worked example "Design: more a's than b's", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The string a has one surplus a and is accepted; aab has one surplus and is accepted; ab cancels to nothing and is rejected, as is the empty string. All four match the strict inequality.

89. Answer it before you see the options: Check yourself: design

Prediction

Predict first

Why does the palindrome machine need nondeterminism while the bracket machine does not?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: The midpoint is not marked in the input, so it must be guessed

Why: The bracket machine decides what to do from the current input symbol alone — opening means push, closing means pop. The palindrome machine must switch from pushing to matching at a point the input does not indicate, so it guesses and relies on one branch succeeding.

90. Check yourself: design

Check

Think about what a stack returns and in what order.

Check your understanding

Why does the palindrome machine need nondeterminism while the bracket machine does not?

  • A. The midpoint is not marked in the input, so it must be guessed (correct)
  • B. Palindromes need a larger stack alphabet
  • C. Brackets are a regular language
  • D. The palindrome machine has more states

Answer: A

Why: The bracket machine decides what to do from the current input symbol alone — opening means push, closing means pop. The palindrome machine must switch from pushing to matching at a point the input does not indicate, so it guesses and relies on one branch succeeding.

Why B tempts people
Both use one stack symbol per input symbol plus a marker. The alphabet sizes are comparable and irrelevant to the question.
Why C tempts people
Lesson 11 proved the balanced brackets are not regular, which is why a stack was needed for them too.
Why D tempts people
State count has nothing to do with it. A machine of any size is deterministic exactly when no configuration offers a choice.

91. Deterministic Machines Are Weaker

Section

Section 6

92. What determinism means here

Concept

A machine is deterministic when no configuration ever offers a choice — and with free moves in play that takes two conditions, not one.

  1. For each state, input symbol and stack symbol, at most one move is available.
  2. If a free move is available in a configuration, no input-consuming move may be available there.

The second condition is the one that is easy to overlook. A free move competing with a reading move is a genuine choice, even though only one of them consumes input.

\[ \delta(q,\varepsilon,X) \neq \varnothing \;\Rightarrow\; \delta(q,a,X) = \varnothing \text{ for every } a \]

93. The surprise: the models differ

Concept

For finite automata, Lesson 6 proved nondeterminism added nothing. Here that fails, and the failure is one of the most important facts in the chapter.

The deterministic machines recognize a strictly smaller class. Some context-free languages have no deterministic machine at all.

\[ \text{DPDA languages} \;\subsetneq\; \text{context-free languages} \]

So the subset-construction trick of Lesson 6 must fail here — and seeing why it fails is more instructive than the statement itself.

94. Why the subset construction fails

Intuition

Lesson 6 determinized a finite automaton by making each set of possible states a single state. That worked because there were finitely many such sets.

Here the machine's situation is a state and a stack, and there are infinitely many possible stacks. So the set of possible situations is infinite, and it cannot be packed into a finite state set.

\[ \text{situations} = Q \times \Gamma^{*} \;: \text{ infinite} \]

Worse, the branches may have different stacks, and one stack cannot simulate several at once. That is the structural obstacle, and no cleverer construction gets around it.

95. Teach it back: Why the subset construction fails

Explain it

Discussion prompt

Explain Why the subset construction fails to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

Lesson 6 determinized a finite automaton by making each set of possible states a single state. That worked because there were finitely many such sets.

96. Plan first: A language with no deterministic machine

Step zero

Discussion prompt

A language with no deterministic machine — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Check the language is context-free

Answer:

  1. Check the language is context-free
  2. See what a machine must do
  3. Notice the decision cannot be deferred
  4. See how nondeterminism handles it
  5. Verify the deterministic obstruction is real

97. A language with no deterministic machine

Worked example

The standard witness, and the argument for why determinism fails on it.

\[ L = \{\, a^{n}b^{n} \,\} \;\cup\; \{\, a^{n}b^{2n} \,\} \]

Check the language is context-free

Why: Each half has an easy grammar, and the union is context-free by combining them with a fresh start variable, as Lesson 13 showed.

See what a machine must do

Why: It reads a block of a's and pushes markers. Then the b's arrive, and it must pop one marker per b, or one per two b's — depending on which half the string belongs to.

Notice the decision cannot be deferred

Why: The rate of popping must be chosen when the first b is read, but which rate is correct is determined only by how many b's eventually arrive.

\[ \text{decide at the first } b \;\text{, learn the answer at the last} \]

See how nondeterminism handles it

Why: A nondeterministic machine guesses the rate at the switch and runs both branches. One of them is correct, and acceptance needs only that one.

Verify the deterministic obstruction is real

Why: A deterministic machine has exactly one computation, so it must commit to one rate with no information distinguishing the cases. Whichever it picks, strings of the other half are rejected — so no single deterministic machine accepts both halves.

\[ \text{one computation} \;+\; \text{two possible rates} \;\Rightarrow\; \text{failure} \ \checkmark \]

98. A language with no deterministic machine — line by line

Picture it

Animation

Shows: Each line of the worked example "A language with no deterministic machine", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Each half has an easy grammar, and the union is context-free by combining them with a fresh start variable, as Lesson 13 showed.

99. Deterministic languages are closed under complement

Concept

One closure property separates the deterministic subclass sharply from the full class, and it is proved much as in Lesson 4.

A deterministic machine has exactly one computation per input, so swapping accepting and non-accepting states negates every verdict — provided the machine always finishes reading the input.

\[ \text{one computation} \;\Rightarrow\; \text{swapping } F \text{ negates the answer} \]

Two technical repairs are needed first: the machine must not get stuck, and it must not loop forever on free moves. Both are fixable by adding a dead state and bounding the free-move chains.

The general context-free languages have no such property, as Lesson 19 shows — which makes this closure a genuine mark of the deterministic subclass rather than a convenience.

100. By analogy: Deterministic languages are closed under complement

Analogy

Discussion prompt

Explain Deterministic languages are closed under complement by analogy to something with no Theory of Computation in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

One closure property separates the deterministic subclass sharply from the full class, and it is proved much as in Lesson 4.

101. What has to happen first: Use complement closure to separate the classes

Ranking

Put in order

Put the moves of Use complement closure to separate the classes into the order they have to happen.

  1. Take a context-free language whose complement is not context-free
  2. Suppose it had a deterministic machine
  3. Derive the contradiction
  4. Verify the argument needs no explicit machine analysis

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Lesson 19 exhibits one: the complement of the strings consisting of a block written twice.

102. Use complement closure to separate the classes

Worked example

A short argument showing the deterministic subclass is strictly smaller, using closure rather than a direct construction.

Take a context-free language whose complement is not context-free

Why: Lesson 19 exhibits one: the complement of the strings consisting of a block written twice.

Suppose it had a deterministic machine

Why: Then by the closure property just proved, its complement would also have one.

Derive the contradiction

Why: A language with a deterministic machine is certainly context-free, so the complement would be context-free — contradicting the choice of language.

\[ L \text{ deterministic} \;\Rightarrow\; \overline{L} \text{ context-free} \]

Conclude

Why: The language is context-free but has no deterministic machine, so the deterministic subclass is strictly smaller.

Verify the argument needs no explicit machine analysis

Why: Unlike the earlier witness, this argument never inspects a machine's behaviour — it runs entirely on closure properties. Both routes reach the same conclusion, and this one generalizes to any language whose complement escapes the class.

\[ \text{deterministic} \;\subsetneq\; \text{context-free} \ \checkmark \]

103. Use complement closure to separate the classes — line by line

Picture it

Animation

Shows: Each line of the worked example "Use complement closure to separate the classes", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Unlike the earlier witness, this argument never inspects a machine's behaviour — it runs entirely on closure properties. Both routes reach the same conclusion, and this one generalizes to any language whose complement escapes the class.

104. What determinism does buy

Concept

Deterministic machines are weaker, and they are also far more useful in practice. Both facts matter.

PropertyDeterministicNondeterministic
languages recognizeda strict subclassall context-free
closed under complementyesno
parsing timelinearcubic
used by real parsersyesrarely

The complement row is the one to remember. Deterministic machines can be complemented by swapping accepting states, much as in Lesson 4 — and Lesson 19 shows the general context-free languages cannot.

105. Which is which, by Deterministic

Discrimination

Sort into buckets

Sort these by Deterministic, from memory, without looking back at What determinism does buy. Telling them apart on the spot is the skill; the table is only where the answer happens to be written down.

a strict subclass
languages recognized
yes
closed under complement; used by real parsers
linear
parsing time
g1
Deterministic is "a strict subclass" for languages recognized — that is what the table on "What determinism does buy" records, and it is the single property separating this group from the rest.
g2
Deterministic is "yes" for closed under complement, used by real parsers — that is what the table on "What determinism does buy" records, and it is the single property separating this group from the rest.
g3
Deterministic is "linear" for parsing time — that is what the table on "What determinism does buy" records, and it is the single property separating this group from the rest.

106. This is the first place the two models diverge

Intuition

Three model families have now been compared for the effect of nondeterminism, and the answers are not uniform.

ModelNondeterminism adds power?Established in
finite automatanoLesson 6
pushdown automatayesthis lesson
Turing machinesnoLesson 22

So the finite-automaton result was not a general principle, and neither is this one. Each model must be checked separately — which is exactly why Lesson 31's question about polynomial time remains open.

107. Fill in: Nondeterminism adds power? for This is the first place the two models…

Comparison

Comparison matrix

From This is the first place the two models diverge: refill the Nondeterminism adds power? column from what you know. The rest of the table is as it appeared.

ModelNondeterminism adds power?Established in
finite automatanoLesson 6
pushdown automatayesthis lesson
Turing machinesnoLesson 22

108. Rule out three: Check yourself: determinism

Elimination

Eliminate the wrong options

Why can the subset construction not be used to determinize a pushdown automaton?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. The possible situations include a stack, so there are infinitely many of them
  • B. Pushdown automata have no accepting states to redistribute
  • C. The stack alphabet may be infinite
  • D. Free moves make the closure computation non-terminating

Survives elimination: A

Why: The construction turned each set of possible states into one state, which needs the collection of such sets to be finite. Here a situation is a state together with a stack, and stacks are unbounded, so the collection is infinite and cannot be a finite state set.

109. Check yourself: determinism

Check

Think about why Lesson 6's construction does not transfer.

Check your understanding

Why can the subset construction not be used to determinize a pushdown automaton?

  • A. The possible situations include a stack, so there are infinitely many of them (correct)
  • B. Pushdown automata have no accepting states to redistribute
  • C. The stack alphabet may be infinite
  • D. Free moves make the closure computation non-terminating

Answer: A

Why: The construction turned each set of possible states into one state, which needs the collection of such sets to be finite. Here a situation is a state together with a stack, and stacks are unbounded, so the collection is infinite and cannot be a finite state set.

Why B tempts people
Accepting states exist under the final-state convention, and the empty-stack convention converts to it. Acceptance is not the obstacle.
Why C tempts people
The stack alphabet is finite by definition. It is the stack's depth that is unbounded.
Why D tempts people
Epsilon-closure computations terminate here as they did in Lesson 6. The obstacle is the infinity of stack contents, not the closure.

110. Why real parsers accept the restriction

Intuition

Practical parsing tools work only with deterministic languages, and they accept that limitation deliberately.

A deterministic machine parses in time linear in the input, with no backtracking and no ambiguity about which rule applied. A nondeterministic one needs a cubic-time table algorithm and may return several trees.

So language designers arrange for their syntax to be deterministic — adding keywords, delimiters and terminators precisely so that every decision is visible when it must be made. The dangling-else resolutions of Lesson 14 are exactly this discipline in practice.

\[ \text{linear parsing} \;\Longleftarrow\; \text{deterministic syntax, by design} \]

111. Break it if you can: Why real parsers accept the restriction

Counterexample

Discussion prompt

Practical parsing tools work only with deterministic languages, and they accept that limitation deliberately.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

112. Rebuild the recipe: Choosing a machine or a grammar

Ranking

Put in order

These are the steps of Choosing a machine or a grammar, scrambled. Put them back in order before the next slide shows you.

  1. Describing what strings look like: the grammar.
  2. Showing a specific string is in the language: trace the machine, or exhibit a derivation.
  3. Proving a closure property: usually the grammar, since alternatives compose freely.
  4. Building a parser: the grammar, converted to a deterministic machine if the language allows.
  5. Proving a language is not context-free: neither — that is Lesson 18.

Why: This is the order the recipe itself gives. Recalling the sequence without the slide in front of you is the difference between recognising the method and being able to run it — most of what goes wrong in practice is a step done out of turn.

113. Choosing a machine or a grammar

Pattern

Both describe this class, and Lesson 17 proves them equivalent. The choice is by task.

  1. Describing what strings look like: the grammar.
  2. Showing a specific string is in the language: trace the machine, or exhibit a derivation.
  3. Proving a closure property: usually the grammar, since alternatives compose freely.
  4. Building a parser: the grammar, converted to a deterministic machine if the language allows.
  5. Proving a language is not context-free: neither — that is Lesson 18.

The fourth line is where practice lives. Real parsers are deterministic machines derived from grammars, and the restriction to deterministic languages is why some grammars must be rewritten before a parser generator will accept them.

114. Where this shows up: Pushdown Automata

Real world

Discussion prompt

Outside this lesson: where does Pushdown Automata actually turn up? Name one concrete situation — a job, a piece of software someone ships, a decision somebody has to make — and say which part of Choosing a machine or a grammar is doing the work in it.

Hint: Vague is the failure mode here. "Engineering" is not a situation; "deciding whether this build is fast enough to ship" is.

Answer:

Lesson 16 adds one unbounded stack to a finite automaton. It explains why a stack is exactly the right addition and what its last-in-first-out discipline still forbids, then covers transitions that read, pop, and push, with each part optional, and the bottom-marker trick for testing emptiness. It gives the formal seven-tuple and the six-tuple variant, configurations and the computation relation, and the final-state and empty-stack acceptance conventions with conversions in both directions. Designs follow for matched counts, palindromes, two kinds of bracket, and strict inequalities. It closes with the result that deterministic pushdown automata are strictly weaker, giving the standard witness language and explaining why the subset construction cannot be transferred.

115. Connect it up: Pushdown Automata

Connect it up

Draw it

One page, no notation unless you need it: draw how these connect — Why a Stack · The Machine, Informally · The Formal Definition · Acceptance, Two Ways · Designing Machines · Deterministic Machines Are Weaker. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.

116. What you can do now

Recap

You have the recognizer for the context-free languages, and you know the one place its behaviour differs from the finite-automaton story.

SituationMove
something must be matched in reversepush it, then pop against the later part
a phase boundary not marked in the inputa free move, and rely on nondeterminism
the stack must be tested for emptinesspush a bottom marker and test for that
two possible behaviours, chosen too earlythe language may have no deterministic machine
a count must be checked twicea stack cannot — expect Lesson 18 to rule it out

Lesson 17 proves these machines recognize exactly the languages the grammars of Lesson 13 generate, completing the pairing.

Sources

  1. Sipser, Introduction to the Theory of Computation, 3rd ed., Ch. 2.2 (Pushdown automata) — Cengage, 2013.
  2. Hopcroft, Motwani & Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Ch. 6.1-6.4 (Pushdown automata and deterministic PDAs) — Pearson, 2007.
  3. Chomsky, 'Context-free grammars and pushdown storage', MIT Research Laboratory of Electronics Quarterly Progress Report 65 — MIT, 1962.
  4. Ginsburg & Greibach, 'Deterministic context free languages', Information and Control 9(6) — Elsevier, 1966.
  5. Every transition, configuration trace and design in this deck was checked by hand, including the empty-string and odd-length boundary cases. — Verified 2026-08-08.

Want this taught 1-on-1? Alexander tutors Theory of Computation — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108