← Quiz: Regular Grammars and Finite Automata: all 10 questions
Quiz: Regular Grammars and Finite Automata · Question 9 of 10
What does this print? (code)
What does this print?
grammar = {"S": ["aA"], "A": ["aA", "bA", "b"]}
nfa = {}
for x, bodies in grammar.items():
for body in bodies:
target = body[1:] if len(body) == 2 else "F"
nfa.setdefault((x, body[0]), set()).add(target)
print(sorted(nfa[("A", "b")]))
- A.['A']
- B.['F']
- C.['A', 'F']
- D.['b']
Answer & explanation
Correct answer: ['A', 'F']
A → bA gives the arrow to A and A → b gives the arrow to F.
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 →