← Quiz: Tries (Prefix Trees): all 15 questions
Quiz: Tries (Prefix Trees) · Question 11 of 15
What does this print? (code)
What does this print?
root = {}
for w in ["tea", "ten", "to", "in"]:
node = root
for ch in w:
node = node.setdefault(ch, {})
node["$"] = True
print(sorted(root), sorted(root["t"]), len(root["t"]["e"]))
- A.['i', 't'] ['e', 'o'] 1
- B.['t', 'i'] ['e', 'o'] 2
- C.['i', 't'] ['a', 'n', 'o'] 2
- D.['i', 't'] ['e', 'o'] 2
Answer & explanation
Correct answer: ['i', 't'] ['e', 'o'] 2
The root has children i and t. Under t come e (tea, ten) and o (to), and under "te" come a and n.
Can you get the rest right without peeking?
Take the timed Quiz: Tries (Prefix Trees) quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →