PDA Construction for
We want a push-down automaton (PDA) that recognizes strings of the form [ u a w b \quad\text{where } u,w\in{a,b}^*\text{ and }|u|=|w|. ] This is a context-free constraint: the PDA uses its stack to “pair” each symbol of with exactly one symbol of (in reverse order) and then verifies the pairing completes exactly when the input has consumed . A PDA is formally a 7-tuple with transitions that read an input symbol (or ) and replace the stack top. It accepts either by reaching a final state or by emptying the stack. We will use final-state acceptance. 2
Key idea:
- Read and push the whole onto the stack (one stack symbol per input symbol of ).
- When the middle delimiter is read, switch to a phase where we read exactly while popping one stack symbol per symbol of .
- Require that the stack is back to the bottom marker exactly when the next delimiter is read.
- Accept only if and had equal length.
We can view the workflow as a 3-phase PDA:
Keywords: pushdown automaton , stack , bottom-of-stack marker , [-transition]{def="A PDA move that consumes no input symbol"}.
Footnotes
-
Introduction of Pushdown Automata - GeeksforGeeks - Defines PDAs, stack-based recognition of context-free languages, and formal PDA notion. ↩
-
Pushdown automaton (Wikipedia) - Covers formal PDA definition and acceptance by final state or empty stack, plus transition concepts. ↩
PDA Example: {0^n 1^n} (Stack pairing intuition)
Formal language restatement
Let . The language is [ L={, u a w b \mid u\in\Sigma^,\ w\in\Sigma^,\ |u|=|w| ,}. ] So any accepted string has:
- An delimiter at position ,
- A delimiter at the end (right after ),
- The number of symbols in equals the number of symbols in .
This “equal-length” property is exactly what the stack can enforce: push items; pop one per symbol of ; ensure the stack returns to its initial bottom marker when ends.
Acceptance by final state is described in standard PDA definitions.
Keywords: context-free language , NPDA , accepting configuration.
Footnotes
-
Pushdown automaton (Wikipedia) - Covers formal PDA definition and acceptance by final state or empty stack, plus transition concepts. ↩
PDA design lifecycle (constructive approach)
Push $u$
Phase 1Read an arbitrary prefix and push each symbol."
Guess the middle delimiter
Phase 2Use nondeterminism to decide where the delimiter 'a' occurs."
Pop while reading $w$
Phase 3For each symbol in $w, pop exactly one stack symbol."
Match trailing 'b' and accept
Phase 4Accept only if stack is back to bottom marker when 'b' is read."
PDA for
We present an NPDA that accepts by final state.
Construction
Let
- where:
- is the bottom-of-stack marker,
- and encode symbols pushed from the input (encoding details are arbitrary but explicit here).
- Start state
- Initial stack symbol
- Accepting states
We will include nondeterminism in when we decide to consume the middle delimiter . Concretely, in the pushing phase, on reading an we may either:
- push it as part of , or
- treat it as the delimiter that starts the -region.
Transition function
We use the standard PDA transition notation: [ \delta(q, x, \text{top}) \ni (q', \text{stack-replacement}) ] meaning: in state , reading input symbol (or ), if the stack top is , then pop it and push (possibly ), move to .
(1) Pushing phase: read and push everything
In state :
- On input or , push an encoded symbol and stay in : [ \delta(q_{\text{push}}, a, Z)\ni(q_{\text{push}}, AZ),\quad \delta(q_{\text{push}}, a, A)\ni(q_{\text{push}}, AA),\quad \delta(q_{\text{push}}, a, B)\ni(q_{\text{push}}, AB) ] [ \delta(q_{\text{push}}, b, Z)\ni(q_{\text{push}}, BZ),\quad \delta(q_{\text{push}}, b, A)\ni(q_{\text{push}}, BA),\quad \delta(q_{\text{push}}, b, B)\ni(q_{\text{push}}, BB) ]
Additionally, nondeterministically choose the delimiter:
- If the next symbol is and the current top is anything, we may instead consume that as the middle delimiter and switch to the popping phase without changing the stack: [ \delta(q_{\text{push}}, a, Z)\ni(q_{\text{pop}}, Z),\quad \delta(q_{\text{push}}, a, A)\ni(q_{\text{pop}}, A),\quad \delta(q_{\text{push}}, a, B)\ni(q_{\text{pop}}, B) ]
This nondeterminism ensures we can select the correct that is exactly after .
(2) Popping phase: read while popping exactly one per symbol
In state :
- For each input symbol in , pop one stack symbol (top can be , ), and stay in : [ \delta(q_{\text{pop}}, a, A)\ni(q_{\text{pop}}, \varepsilon),\quad \delta(q_{\text{pop}}, a, B)\ni(q_{\text{pop}}, \varepsilon) ] [ \delta(q_{\text{pop}}, b, A)\ni(q_{\text{pop}}, \varepsilon),\quad \delta(q_{\text{pop}}, b, B)\ni(q_{\text{pop}}, \varepsilon) ]
We do not allow or to be consumed when the stack top is , because that would mean continues even though is exhausted. (This is what enforces .)
(3) Final delimiter: read trailing and accept iff stack is back at
After popping exactly symbols, the stack top will be . Then: [ \delta(q_{\text{pop}}, b, Z)\ni(q_f, Z) ] and we accept in after consuming the final .
This enforces the input ends right after the delimiter and that had exactly length .
Keywords: NPDA nondeterminism , LIFO , stack encoding.
Run of $M$ on a string $uaw b$ (acceptance proof idea)
- 1Step 1
While in , for each symbol of read, push a corresponding marker onto the stack. After reading , the stack height equals plus the bottom marker.
- 2Step 2
Use the nondeterministic delimiter transition to read the specific that is immediately after and switch to without altering the stack.
- 3Step 3
For each symbol of , read that symbol in and pop exactly one stack symbol. After reading all of , exactly pops have occurred.
- 4Step 4
If , then the stack will be back to the bottom marker when ends; then the next input symbol must be the trailing .
- 5Step 5
On reading the trailing with stack top , take the transition to . This yields acceptance; otherwise no transition exists and the branch rejects.
- 6Step 6
If , then at input end the stack is not back to (so no accepting move is possible). If , you eventually try to read symbols in while the stack top is ; no transition exists for that, so the branch dies.
Pro Tip: Use nondeterminism to locate the delimiter
Because can be any length, the PDA cannot know in advance which is the delimiter. The transitions in intentionally allow both pushing that into or treating it as the middle delimiter.
Do not allow popping-phase moves when top is $Z$
In , forbid transitions that would read extra symbols of when the stack top is . This is exactly what enforces .
Why this PDA recognizes exactly
Soundness ( accepts only strings in ):
- The only way to leave to is by consuming an input as the middle delimiter.
- The PDA can only consume symbols in by popping stack symbols; hence, the number of consumed symbols of cannot exceed the number of pushed symbols from .
- The only way to enter acceptance is by consuming a trailing while the stack top is , meaning all pushes from were popped exactly—so . Therefore, any accepted string must be of the form with .
Completeness ( accepts every string in ):
- Given any with , there exists a computation branch where the PDA:
- pushes exactly the characters of ,
- uses the delimiter transition on the correct after ,
- pops once per character of ,
- finally consumes the trailing when the stack is back to . This branch reaches and accepts.
Keywords: soundness , completeness.
Common variations and checks
Length relationship enforced by the stack
Stack height after pushing equals ; each symbol of decreases it by 1.
Knowledge Check
Which action enforces the condition ?
Explore Related Topics
CYK Membership Test for the String “baaba”
Minimization of Automata
Converting the Regular Expression $(a+b)^*ab$ into an NFA
The course shows how to turn the regular expression —the set of all strings over that end with “ab”—into an NFA, first via Thompson’s systematic ε‑construction and then with a minimal three‑state NFA.
- Thompson’s construction builds ε‑transitions for symbols , , their union, the Kleene star, and the final concatenations, yielding a 12‑state ε‑NFA.
- A compact direct NFA uses only three states: loops on , branches on to , and moves on to accepting .
- The compact NFA’s transition table illustrates nondeterministic moves (e.g., ) and accepts exactly the strings ending in “ab”.
- State‑complexity comparison: Thompson’s method needs many states and ε‑moves, while the direct NFA is far smaller and easier to simulate.