In a pushdown automaton, what is the difference between accepting by empty stack and accepting in a final state?
answer
- two conventions for a successful run
- store exhausted versus control state
- same class when guessing is allowed
- a private bottom marker converts one way
- forced moves plus empty store means prefix-free
basics
~20 sAccepting by empty stack ends a successful run with the store exhausted, wherever the control sits; accepting in a final state ends it in a designated state, whatever the store holds. For machines that may guess, the two conventions describe the same languages.
solid answer
~40 sBoth are conventions for declaring a run successful, and for the guessing model they are interchangeable. To turn empty-store acceptance into final-state acceptance, push a **private bottom marker** before anything else and move to an accepting state the moment that marker surfaces; to go the other way, add a state that pops the store clean once an accepting state is reached. The symmetry breaks for machines with one forced move per configuration: such a machine accepting by empty store has no move left the instant the store empties, so it can never accept both a word and a longer word that starts the same way - its language is **prefix-free**. In reader terms that is the difference between a frame that ends exactly where its nesting closes and one that needs an explicit terminator.
go deeper
Know that a model needs a rule for when a run succeeds, and that there are two: the store has been emptied, or the control finished in a designated state.
Explain both conversions and why the bottom marker is needed. State that in the guessing model the conventions accept the same class, so neither is stronger.
Connect it to framing: a self-delimiting frame ends where its nesting closes and is prefix-free, while a terminated frame keeps reading past depth zero. Mixing the two hangs a reader on valid input.
The design call is whether frames are self-delimiting. That choice fixes whether a streaming reader can be single-pass and forced-move, and it is far cheaper to make before the format ships than after.
A machine model needs a rule for when a run counts as successful, and the pushdown model has two in common use. Knowing that they are usually equivalent - and knowing the one case where they are not - is what separates someone who has used the model from someone who has only seen the picture. ## The two conventions - **Acceptance in a final state.** Some states are designated accepting. A run succeeds if the input is fully consumed and the control is in one of those states. The store may hold anything at all. - **Acceptance by empty stack.** There are no designated states. A run succeeds if the input is fully consumed and the store has been exhausted. Where the control sits is irrelevant. Neither is more 'real' than the other. They are bookkeeping choices, and textbooks and proofs pick whichever makes the construction at hand shorter. ## Converting each into the other 1. **Empty store to final state.** Add a fresh start state that pushes a **private bottom marker**, a symbol the original machine never pushes, and then hands over to the original start configuration. Add one accepting state, reached by a move that consumes no input whenever the marker is on top. The marker can only surface once everything the original machine pushed is gone, which is exactly the original acceptance condition. 2. **Final state to empty store.** Add a cleanup state, reachable by a move that consumes no input from every accepting state, whose only job is to pop symbols until nothing is left. The store empties precisely on the runs the original accepted. Step 1 is the one that is easy to get wrong. Without the private marker the simulating machine cannot tell 'the original machine's store is empty' from 'my own bookkeeping ran out', and it could declare success in the middle of a run. | | acceptance in a final state | acceptance by empty stack | |---|---|---| | what is checked | control state at end of input | store exhausted at end of input | | store at the end | unconstrained | necessarily empty | | guessing model | context-free languages | the same class | | forced-move model | the deterministic subclass | only its prefix-free members | | natural fit | a frame with a terminator | a self-delimiting frame | ## Where determinism breaks the symmetry A machine with at most one applicable move per configuration cannot continue once its store is empty: every step must consult a top symbol, and there is none. So an accepted word cannot be extended - if `w` is accepted, no longer word starting with `w` can be, because the machine stopped. A language with that property is called **prefix-free**: no member is a proper prefix of another member. That single consequence is the whole asymmetry. The guessing model dodges it because a guessing machine can keep a reserve symbol on the store along one branch while another branch empties it, so it never has to choose between stopping and continuing. ## Why a reader author should care The two conventions correspond to two real framing strategies: - **Self-delimiting frames.** The frame ends where its nesting closes, so a reader streaming bytes knows it is done the moment depth returns to zero, without a length prefix and without a terminator. Such a format is prefix-free by construction, which is exactly why a forced-move reader can handle it. - **Terminated frames.** The frame ends at an explicit marker, so the reader keeps going after depth reaches zero until it sees the terminator. Here 'done' is a control condition, not a store condition. Mixing them is a classic interoperability bug: a producer that emits self-delimiting frames back to back and a reader that waits for a terminator will hang on perfectly well-formed input, and neither side's tests catch it because each is internally consistent. ## Things worth saying precisely - The conventions change **nothing** about which languages the guessing model accepts; a candidate who claims one is stronger has not seen the conversions. - A private bottom marker is part of the stack alphabet, never the input alphabet - the input can never contain it, which is what makes it a reliable signal. - A third convention, requiring an accepting state **and** an empty store together, also accepts the same class in the guessing model: convert to final-state acceptance, then insert a cleanup phase before entering the accepting state. - Rejection is not the negation of a single run. In the guessing model a word is accepted if **some** run accepts, so a rejected word is one where **every** run fails, which is why turning a guessing machine into a rejector is not a matter of flipping the accepting states.
- Why does the conversion need a bottom marker the input can never contain?Because the simulating machine must not confuse the original machine's store running out with its own bookkeeping running out. A marker pushed before anything else surfaces only when everything the original pushed has gone, which is exactly the moment to declare success. Drawing it from the input alphabet would let real input imitate the signal.
- What does prefix-free mean, and why does empty-store acceptance force it on a forced-move machine?Prefix-free means no accepted word is a proper prefix of another accepted word. A machine with one forced move per configuration has no move left once the store is exhausted, since every step must read a top symbol, so it cannot read on and accept a longer word with the same start. Streaming formats exploit this: a self-delimiting frame tells the reader where it ends without a length or a terminator.
- Can a model require both an accepting state and an empty store?Yes, and in the guessing model it accepts the same class as either condition alone. Convert to final-state acceptance, then route every accepting state through a cleanup phase that empties the store before the run is declared successful. The convention is a modelling choice, not a change in power.
saying these in an interview costs you the question
- Says a run accepted by empty store must also end in a final state
- Claims the two conventions accept different classes in the guessing model
- Believes a forced-move machine gains power from the empty-store convention
- Forgets that an exhausted store leaves a forced-move machine with no move
- Assumes the bottom marker comes from the input alphabet
- Treats rejection as one failed run rather than every run failing