RTUComputer ScienceYr 2023 · Sem 42023

Q6Theory of Computation

Question

4 marks

Design a PDA for L = {a^n b^{2n} | n ≥ 1}.

Answer

A single-stack PDA pushes a marker for every a and pops two markers per b, accepting by empty stack exactly when the count of b's is twice the count of a's.

consists of strings with a block of a's followed by a block of exactly b's. A PDA can recognize this by using the stack to count: push one symbol for each 'a' read, then pop two symbols for every 'b' read (since each 'a' must be matched by two 'b's). The string is accepted if, after consuming all input, the stack is empty (having popped exactly what was pushed) and at least one 'a' was read.

Define the PDA with , , , start state , initial stack symbol , and (acceptance by final state, on empty operand stack above ). The transitions are:

  • — push A for the first 'a', replacing with .
  • — push another A for each subsequent 'a'.
  • — on seeing a 'b', pop the top A (this is the first of the two b's assigned to that A) and move to state .
  • — on seeing the second 'b' for the same A, leave the stack unchanged and return to , ready for the next A's pair of b's (or end of input).
  • — if the stack is back to just (all A's popped) and input is exhausted, move to the accepting state .

For input (, so b's are expected): start . Read 'a': push A, giving . Read 'a': push A again, giving . Now each A on the stack must absorb exactly two b's via the toggle. Read first 'b': pop the top A, move to : . Read second 'b': this second b for the same A returns control to without popping further (the toggle only pops on entry to ), giving . Read third 'b': pop the remaining A, move to : . Read fourth 'b': return to : . Input is now empty and the stack holds only , so fires, moving to , and is accepted.

The stack height after reading the a-block equals (the number of a's), and each toggle consumes exactly two b's while popping exactly one A, so the machine can consume exactly b's before the stack returns to bare ; reading more or fewer b's leaves either a non-empty stack of A's (input exhausted with no -move to possible, since that move requires on top) or an empty stack while b's remain unconsumed (no valid transition, since on has no move on 'b'), so the PDA accepts if and only if for some . This PDA has one stack symbol type per counted quantity, illustrating the general technique for context-free languages defined by a fixed integer ratio between two blocks of symbols, and confirms via the pushdown-automata/context-free-grammar equivalence that is context-free, matching the grammar .

Back to Paper