← Quiz: NFA and Subset Construction: all 10 questions
Quiz: NFA and Subset Construction · Question 8 of 10
What does this print? (code)
What does this print?
eps = {"A": {"B"}, "B": {"C"}, "C": set(), "D": {"A"}}
def closure(q):
seen, todo = {q}, [q]
while todo:
for r in eps[todo.pop()]:
if r not in seen:
seen.add(r)
todo.append(r)
return sorted(seen)
print(closure("B"), closure("D"))
- A.['B'] ['D']
- B.['B', 'C'] ['A', 'D']
- C.['B', 'C'] ['A', 'B', 'C', 'D']
- D.['A', 'B', 'C'] ['A', 'B', 'C', 'D']
Answer & explanation
Correct answer: ['B', 'C'] ['A', 'B', 'C', 'D']
ε-closure includes the state itself and everything reachable by ε-moves only.
Can you get the rest right without peeking?
Take the timed Quiz: NFA and Subset Construction quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →