Constructing a PDA for (Final State and Empty Stack)
We want a pushdown automaton (PDA) for the context-free language
Intuitively: read an even number of ’s (possibly ), then match a single , then a single , and reject anything else.
We will build two equivalent machines:
- one that accepts by final state (using an accepting state),
- one that accepts by empty stack (by popping the entire stack).
Key notions:
- pushdown automaton (PDA)
- acceptance by final state
- acceptance by empty stack
- instantaneous description
Formally, acceptance modes are defined using the PDA’s transition relation and either an accepting state set (final state) or the condition that the stack becomes empty (empty stack). 2
Footnotes
-
Pushdown automaton - Definitions and acceptance modes (final state vs empty stack) for PDAs. ↩
-
Lecture 14 – Pushdown Automata (PDA) - COSE215 - Formal definitions of acceptance by final states and by empty stacks with illustrative PDA transition examples. ↩
PDA Acceptance by Final State and Empty Stack (overview)
Strategy to recognize
Use the stack to “count pairs of ’s”:
- For each input symbol , push an onto the stack.
- When arrives, pop exactly one per previously seen ; but because we need even many ’s, we can enforce pairing by pushing per and requiring that after processing the we can only proceed if exactly the “pairing structure” allows an acceptance.
A simpler, deterministic-feeling construction is:
- while reading ’s, push one for each ,
- when is read, pop two ’s per “unit step” is awkward because occurs only once. Instead, we implement a standard technique: push two markers per pair of ’s by consuming ’s in pairs using an intermediate state.
Concretely:
- State : expect the first of a pair.
- State : after seeing one of a pair, expect the second and then push a marker representing one completed pair.
- After any number of completed pairs, transition to the -reading state, then to -reading state, and then accept (or empty the stack, depending on the acceptance mode).
Build NPDA (nondeterministic PDA) transitions for $a^{2n}bc$
- 1Step 1
Start with stack bottom symbol ; initially the machine has on the stack (used to detect when the stack should be empty at the end for empty-stack acceptance).
- 2Step 2
Use two states so that one is stored implicitly (by moving states), and the second causes one stack push of a pair-marker .
- 3Step 3
From the state reached after completing a pair (or from the path), read a single and move to -reading.
- 4Step 4
From the -reading state, either (final-state) enter an accepting state, or (empty-stack) pop the remaining pair-markers and so that the stack becomes empty.
- 5Step 5
Ensure there are no transitions for any other symbol sequences (e.g., another , or an extra after ).
PDA #1: Acceptance by final state
We define (a 7-tuple with accepting states ).
Let:
- start state
- initial stack symbol
- accepting states
Interpretation:
- : either begin a pair by reading the first , or if no ’s exist (), go directly to reading .
- : we have read exactly one of the current pair; now we must read the second to complete the pair and push .
- : we have completed pairs; now either start another pair or go to read .
- : read exactly one .
- : read exactly one .
- : accept.
Transition function (written as: )
Key transitions:
- Pairing ’s (push one per pair )
-
-
(allow reading first whether stack top is or ) -
-
(upon second , push on top)
- Move to reading after finishing pairs
-
For (no read): from , read with stack unchanged:
(the -case won’t be reachable for in a correct run, but it keeps the definition total)
-
For : from , read without changing stack:
- Read and accept (final-state)
- No other transitions allow continuation In particular, we do not provide transitions for:
- reading in or ,
- reading in ,
- reading any symbol after reaching .
Why this works (sketch)
- Each completed pair pushes exactly one , so runs with an odd number of ’s get stuck in waiting for the second .
- After all pairs, exactly one is consumed, then exactly one is consumed.
- For , the machine reads immediately from , then .
This recognizes precisely by reaching after consuming the input. 2
Footnotes
-
Pushdown automaton - Definitions and acceptance modes (final state vs empty stack) for PDAs. ↩ ↩2
-
Lecture 14 – Pushdown Automata (PDA) - COSE215 - Formal definitions of acceptance by final states and by empty stacks with illustrative PDA transition examples. ↩
PDA #2: Acceptance by empty stack
Now we build a PDA that accepts by empty stack, i.e., after consuming the entire input it reaches a configuration with empty stack (stack content ). 2
Let:
- start state
- initial stack symbol
- no accepting states needed for empty-stack acceptance (acceptance is by stack emptiness).
Transitions mirror the pair-building from , but after reading we pop all stack symbols until empty.
- Pair ’s (same logic)
- After pairs, read exactly one , then exactly one
-
path:
-
path:
-
-
- Empty the stack after consuming Let be the state that starts popping:
(pop a )
(pop bottom symbol to truly empty the stack)- No further input should be consumed after this; because the stack becomes empty, acceptance-by-empty-stack is satisfied immediately when the computation ends.
Thus, for every string , the machine pushes one per pair, consumes then , and then empties the stack; for any string not in the language, it fails to reach empty stack. 2
Footnotes
-
Pushdown automaton - Definitions and acceptance modes (final state vs empty stack) for PDAs. ↩ ↩2
-
Lecture 14 – Pushdown Automata (PDA) - COSE215 - Formal definitions of acceptance by final states and by empty stacks with illustrative PDA transition examples. ↩ ↩2 ↩3 ↩4
Visual transition logic (pairing ’s)
type="tip" title="Pro Tip" content="When a language constrains parity (like ), model the parity by consuming input in fixed-size chunks (here, pairs ). Using two states () is a clean way to guarantee that odd-length -prefixes get stuck."
type="warning" title="Common Mistake" content="Don’t try to “count evenness” by pushing on every and popping only once at the end—because there is only one and one , you must structure the PDA so the -processing phase enforces the even constraint before transitioning to the fixed middle/end symbols."
Acceptance mechanism comparison
Same language, different acceptance condition.
Correctness notes & edge cases
How the PDA processes input
Pair up $a$’s
Phase 1Use to ensure ’s come in pairs; push one per pair."
Match the single $b$
Phase 2From either (for ) or (for ), read exactly one ."
Match the single $c$
Phase 3From , read exactly one ."
Accept
Phase 4Final-state PDA enters ; empty-stack PDA pops ’s and until the stack is empty."
Knowledge Check
In the PDA construction for , which structural idea enforces that the number of ’s is even?
Explore Related Topics
N-Queens Backtracking Pseudocode: A Comprehensive Explanation
When Can a Language Be Accepted by a Turing Machine?
Banker's Algorithm Safe-State Analysis for Processes $P_0$ Through $P_4$
The course walks through a full Banker's‑algorithm safety analysis for processes –, computing the Need matrix and using the work‑vector test to verify a safe state and a valid completion order.
- Need matrix: , , , , .
- Starting work ; each step selects a process with , releases its allocation, and updates .
- All processes finish, yielding a safe sequence .
- A safe state requires only one such sequence; it does not mean every immediate allocation is safe.
- Exam tip: test processes with minimal or zero Need first to unlock the rest.