Back to the 2026 paper

Module 2: Syntax Analysis (Parser)

20267m

Construct a transition diagram for the Pushdown Automaton for the language:
L={wcwR∣w∈{a,b}∗}L = \{ wcw^R \mid w \in \{a, b\}^* \}

Worked SolutionAI Assisted

PDA for L={wcwR∣w∈{a,b}∗}L = \{ w c w^R \mid w \in \{a,b\}^* \}

Idea

  1. In state q0q_0, push every symbol of ww on the stack.
  2. On reading the middle marker c, move to q1q_1 without touching the stack.
  3. In q1q_1, each input symbol must match the stack top; pop it. This checks the second half is wRw^R (the stack reverses ww).
  4. When the input is finished and only Z0Z_0 remains, move to the accepting state q2q_2.

Formal definition: M=({q0,q1,q2},{a,b,c},{a,b,Z0},δ,q0,Z0,{q2})M = (\{q_0,q_1,q_2\}, \{a,b,c\}, \{a,b,Z_0\}, \delta, q_0, Z_0, \{q_2\}) (acceptance by final state).

Transition function δ\delta (notation: input, stack top / new stack top)

# Move
1 δ(q0,a,Z0)=(q0,aZ0)\delta(q_0, a, Z_0) = (q_0, aZ_0)
2 δ(q0,b,Z0)=(q0,bZ0)\delta(q_0, b, Z_0) = (q_0, bZ_0)
3 δ(q0,a,a)=(q0,aa)\delta(q_0, a, a) = (q_0, aa)
4 δ(q0,a,b)=(q0,ab)\delta(q_0, a, b) = (q_0, ab)
5 δ(q0,b,a)=(q0,ba)\delta(q_0, b, a) = (q_0, ba)
6 δ(q0,b,b)=(q0,bb)\delta(q_0, b, b) = (q_0, bb)
7 δ(q0,c,X)=(q1,X)\delta(q_0, c, X) = (q_1, X) for X∈{Z0,a,b}X \in \{Z_0, a, b\}
8 δ(q1,a,a)=(q1,ε)\delta(q_1, a, a) = (q_1, \varepsilon)
9 δ(q1,b,b)=(q1,ε)\delta(q_1, b, b) = (q_1, \varepsilon)
10 δ(q1,ε,Z0)=(q2,Z0)\delta(q_1, \varepsilon, Z_0) = (q_2, Z_0)

Transition diagram

MermaidDiagram
Rendering diagram…

Trace for abcba

State Remaining input Stack (top left) Move
q0q_0 abcba Z0Z_0 push a
q0q_0 bcba aZ0aZ_0 push b
q0q_0 cba baZ0baZ_0 read c, go to q1q_1
q1q_1 ba baZ0baZ_0 b matches, pop
q1q_1 a aZ0aZ_0 a matches, pop
q1q_1 ε\varepsilon Z0Z_0 ε\varepsilon-move to q2q_2
q2q_2 ε\varepsilon Z0Z_0 accept

A string such as abcab is rejected: after c the stack top is b but the input is a, so no move exists. The PDA is deterministic because c marks the middle.

Similar questions

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.