Consider the NPDA ({q0, q1, qf}, {a, b}, {1, z}, δ, q0, z, {qf}) with δ(q0, λ, z) = {(qf, z)}, δ(q0, a, z) = {(q1, 11z)}, δ(q1, a, 1) = {(q1, 111)}, δ(q1, b, 1) = {(q1, λ)}, δ(q1, λ, z) = {(qf, z)}. Which language does it accept?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. {aⁿb²ⁿ : n ≥ 0}
Explanation
Each a adds two 1's to the stack and each b removes one, so 2n b's are needed for n a's. The empty string is accepted directly from q0, so n ≥ 0.
Note on the official key: the official key says option A. Official/PW key is A ({a²ⁿbⁿ : n ≥ 0}). Each a pushes two 1's and each b pops one, so the machine needs twice as many b's as a's: {aⁿb²ⁿ}.
More Theory of Computation and Compilers questions
- Consider two PCP instances over {0, 1}, each with lists A and B of three strings. X: A = (1, 10111, 10), B = (111, 10, 0). Y: A = (10, 011,…
- Match List I with List II. List I: (A) Activation record, (B) Location counter, (C) Reference count, (D) Address relocation. List II: (I) L…
- Consider the grammar S → SbS | a. The string abababa has (A) two parse trees (B) two leftmost derivations (C) two rightmost derivations. Wh…
- Match List I with List II. List I: (A) Type 0, (B) Type 1, (C) Type 2, (D) Type 3. List II: (I) Finite automata, (II) Turing machine, (III)…
- Statement I: The LALR parser is more powerful than the canonical LR parser. Statement II: The SLR parser is more powerful than LALR. Which…
- Statement I: CFLs are closed under homomorphism. Statement II: CFLs are closed under complement. Which is correct?