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

Quiz: Regular Grammars and Finite Automata · Question 4 of 10

What does this print? (code)

What does this print?

delta = {("A", "0"): "B", ("A", "1"): "A", ("B", "0"): "B", ("B", "1"): "C",
         ("C", "0"): "B", ("C", "1"): "A"}
form, state = "A", "A"
for ch in "001":
    state = delta[(state, ch)]
    form = form[:-1] + ch + state
print(form)
  1. A.001A
  2. B.001B
  3. C.001C
  4. D.001
Answer & explanation

Correct answer: 001C

The run A → B → B → C gives the sentential form 001C; C → ε would finish it.

Can you get the rest right without peeking?

Take the timed Quiz: Regular Grammars and Finite Automata quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →