- 2070 Chaitra
PDA for palindromes over {a,b}
Short answer
Push each symbol onto stack. Nondeterministically guess the middle by an epsilon-transition (even length) or skip one symbol (odd). Then match and pop. Accept if Z0 remains at end.
Design a PDA that accepts all palindromes defined over {a, b}*.
A palindrome reads the same forwards and backwards: wwᴿ (even length) or w a wᴿ / w b wᴿ (odd length, middle symbol a or b), including ε.
Idea (nondeterministic): push the first half onto the stack. At a guessed middle point, move to a second state (for odd length, skip the middle symbol). Then match each input symbol with the stack top, popping.
M = ({q0, q1, qf}, {a, b}, {a, b, Z0}, δ, q0, Z0, {qf}), with X standing for any of a, b, Z0.
| # | Transition | Meaning |
|---|---|---|
| 1 | δ(q0, a, X) ∋ (q0, aX) | push a |
| 2 | δ(q0, b, X) ∋ (q0, bX) | push b |
| 3 | δ(q0, ε, X) = {(q1, X)} | guess middle (even length) |
| 4 | δ(q0, a, X) ∋ (q1, X) | middle symbol a (odd length), not pushed |
| 5 | δ(q0, b, X) ∋ (q1, X) | middle symbol b (odd length), not pushed |
| 6 | δ(q1, a, a) = {(q1, ε)} | match a |
| 7 | δ(q1, b, b) = {(q1, ε)} | match b |
| 8 | δ(q1, ε, Z0) = {(qf, Z0)} | accept |
a,X/aX b,X/bX a,a/ε b,b/ε
↺ ε,X/X ↺
──► (q0) ─────────────► (q1) ──ε,Z0/Z0──► ((qf))
└── a,X/X or b,X/X ──►
(skip odd middle)
Rules 1 and 4 (and 2 and 5) give two choices on the same input, e.g. δ(q0, a, X) = {(q0, aX), (q1, X)}; the PDA is non-deterministic, and a string is accepted if some sequence of choices works.
Examples
- abba: push a, b; guess the middle by an ε-move; read b (pop b), a (pop a); Z0 is exposed, accept.
- aba: push a; read b as the middle (no push); read a (pop a); accept.
- ab: push a; neither choice can match b against a, so it is rejected.
- ε: q0 → q1 by an ε-move → qf, accepted.
A PDA is needed (not a finite automaton) because the machine must remember the whole first half, whose length is unbounded.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- TM configuration; TM for palindromes · Theory of Computation, chapter 4
- PDA configuration; PDA for a^(3n)b^n · Theory of Computation, chapter 3
- PDA for aⁿb^(3n) · Theory of Computation, chapter 3
- PDA for a^n b^(n+m) c^m · Theory of Computation, chapter 3
- PDA for aⁱbʲcᵏ with i = j + k · Theory of Computation, chapter 3
- PDA for aⁿb^(2n+1) · Theory of Computation, chapter 3
- Initial line design for 200 MW over 120 km · Transmission and Distribution System Design, chapter 2
- Design FSA accepting even number of a's · Discrete Structure, chapter 2 · asked 4×
- Design FSA accepting odd number of b's · Discrete Structure, chapter 2 · asked 4×
- Define FSM; design FSA with two consecutive a's · Discrete Structure, chapter 2 · asked 4×