skip to content

Why can some languages be accepted by a nondeterministic pushdown automaton but by no deterministic one?

level: seniorimportance: should knowfreq 37%

answer

  1. at most one move per configuration
  2. the switch point is not announced
  3. guessing tries every midpoint at once
  4. a centre marker forces the move
  5. strictly smaller than the full class

basics

~20 s

A deterministic machine must commit at every step, and some languages hide the point where pushing should turn into popping. Even-length words that read the same both ways carry no midpoint marker, so only a machine allowed to guess accepts them.

solid answer

~50 s

A **deterministic** pushdown automaton has at most one applicable move in every configuration, so its behaviour on an input is a single forced run. Take the even-length words over two letters that read the same forwards and backwards: to accept one, the machine must push the first half and pop the second, which means committing to a switch at the exact midpoint - and nothing in the input announces it. A guessing machine tries the switch at every position and accepts if any branch works; a forced-move machine has one shot and no evidence. So the deterministic subclass is **strictly smaller** than the full class, which is not true of finite-state machines, where determinising costs states but no power. Insert a distinct centre symbol and the same language becomes deterministic, which is the whole argument for self-describing framing.

go deeper

for a junior

Know that a deterministic machine has one forced move at each step, and that some languages need a machine allowed to try alternatives instead.

for a middle

Explain the mirrored-word example: the switch from recording to checking sits at an unannounced midpoint, and a forced-move machine has no evidence for where it is.

for a senior

Draw the design conclusion: put markers, lengths or tags in the format so a reader's moves are forced, and its cost per byte becomes predictable instead of search-shaped.

for a principal

The trade you own is information in the format against intelligence in the reader. Paying a few bytes per region buys every reader in the ecosystem a single forced pass, and that bargain is hard to renegotiate later.

For finite-state recognisers, nondeterminism is a convenience: every nondeterministic machine has a deterministic equivalent, at a cost in states. The instinct carries over badly. Adding a store changes the situation, and the difference has a direct consequence for anyone designing a format that must be read in one pass. ## What determinism means for this machine A pushdown automaton is deterministic when, for every configuration, at most one move applies. That requires two conditions: - for each combination of state, input symbol and top stack symbol there is **at most one** move; and - whenever a move that consumes no input applies in a configuration, **no** input-consuming move applies there, so the machine never gets to choose between waiting and reading. Without the second condition a machine could sit on a silent move and a reading move at once, which is a choice in all but name. ## The language that separates the two Consider the even-length words over two letters that read the same forwards and backwards. A machine that accepts them must, at some position, stop recording symbols and start checking them against what it recorded. The store makes the checking easy - the symbols come back in reverse order, which is exactly what is needed. The problem is **when** to switch: 1. The word carries no marker at its centre; both halves are made from the same two letters. 2. A forced-move machine must choose a switching point using only what it has read so far, and nothing it has read distinguishes the true midpoint from any other position. 3. A guessing machine takes every branch at once: at each position it explores both continuing to push and beginning to pop, and the word is accepted if **some** branch consumes the input and ends successfully. So the language is within the class overall, but outside the deterministic subclass. That is a strict containment, and it is the standard example an interviewer expects. ## The one change that fixes it Put a distinct symbol at the centre, a symbol that cannot occur in either half. Now the machine pushes until it reads the marker and pops afterwards, and every step is forced by the current input symbol. The same language shape becomes deterministic because the input now **tells** the reader where the structure turns. This is not a toy observation. Self-describing framing - a length in front of a region, a delimiter between two parts, a tag that names what follows - is the practical version of the same trick. A reader that is told where a region ends never has to guess, and a reader that never guesses can be a single forced pass over the bytes. | property | forced-move machine | guessing machine | |---|---|---| | moves per configuration | at most one | any number | | languages accepted | a strict subset of the class | the whole class | | closed under complement | yes | no | | cost of running it | one step per input symbol | search, or many live configurations | | what a format owes it | markers, lengths, tags | nothing | ## Complement: the compensation The deterministic subclass has a property the full class lacks: it is **closed under complement**. Given a forced-move machine you can build one accepting exactly the inputs the first rejects, once runs that consume no input forever and runs that die early are handled. The full class is not closed under complement, so for a general rule set there may be no rule set describing the inputs it rejects. The practical reading: a deterministic reader can be turned into a precise checker that reports exactly the ill-formed inputs, while a guessing model gives you no such guarantee. ## Nondeterminism is a model, not an implementation A candidate who says 'nondeterminism is just backtracking' has skipped a step. In the model, a word is accepted if some run accepts it; nothing says how that is realised. An implementation must realise it somehow - by searching with backtracking, or by carrying many possible configurations forward together - and both cost more per input symbol than following a forced move. That gap is the reason format designers care: determinism is what makes a reader's cost per byte predictable, and the way to buy it is to put information in the format rather than intelligence in the reader. ## Where this sits relative to finite-state machines The contrast is worth stating explicitly, because the wrong analogy is the usual source of error. Determinising a finite-state machine is always possible and costs only states. Determinising a pushdown machine is sometimes **impossible**, because the store cannot be duplicated across the branches of a guess the way a state set can be combined into one.

  • What single change to a format makes a mirrored region deterministically readable?
    Announce the boundary. A centre marker, or a length in front of the region, turns the switch from recording to checking into a move forced by the current symbol. Self-describing framing is the same idea generalised: a reader that is told where a region ends never has to guess, and so it never has to search.
  • Is the deterministic subclass closed under complement?
    Yes, and the full class is not. A forced-move machine can be converted so that accepting and non-accepting outcomes swap, once runs that consume no input forever and runs that die early are dealt with. That is why a deterministic reader can be turned into a checker reporting exactly the ill-formed inputs, while for a general rule set no rule set for the rejected inputs need exist.
  • Does the guessing model mean a real reader tries every possibility at runtime?
    No. Nondeterminism is a property of the model: a word is accepted if some run accepts. An implementation realises it by searching with backtracking, or by carrying many possible configurations forward at once, and both cost more per input symbol than following a single forced move.
  • Why does the finite-state intuition mislead here?
    Because determinising a finite-state machine is always possible and costs only states, which trains people to treat nondeterminism as bookkeeping. With a store it can be impossible: the branches of a guess each want the single store to themselves, and unlike a state set, stores cannot be merged into one.

saying these in an interview costs you the question

  • Says nondeterminism is merely a faster way of doing the same thing
  • Claims every context-free language has a forced-move machine
  • Thinks the machine can look ahead to the end of the input
  • Says adding a centre marker makes no difference to determinism
  • Confuses the machine's guessing with randomness
  • Assumes determinising works here because it works for finite-state machines