🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: CFG and PDA: all 10 questions

Quiz: CFG and PDA · Question 1 of 10

Which grammar generates {a^n b^n | n ≥ 0}?

Which grammar generates {a^n b^n | n ≥ 0}?

  1. A.S → aS | bS | ε
  2. B.S → aSb | ε
  3. C.S → ab | ba
  4. D.S → aSa | b
Answer & explanation

Correct answer: S → aSb | ε

Each step adds one a on the left and one b on the right.

Can you get the rest right without peeking?

Take the timed Quiz: CFG and PDA quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →