Embercode
✕
TriesQuick quiz

Trie bug hunt

8 questions. Covers Debugging lab: trie bugs.

Questions 1 to 5 of 8

  1. 1. This insert is used for a trie whose nodes hold children, a list of 26 slots, and a boolean is_end. ``python def insert(root, word): node = root for ch in word: idx = ord(ch) - ord("a") if node.children[idx] is None: node.children[idx] = Node() node = node.children[idx] ` After insert(root, "cat"), search(root, "cat") returns False`. What is the bug?
  2. 2. What does this program print? ``python def index(ch): return ord(ch) - ord("a") + 1 print(index("a"), index("z")) ``
  3. 3. This index function is used for a list of 26 children and lowercase words. ``python def index(ch): return ord(ch) - ord("A") ` Inserting cat raises IndexError: list index out of range`. What is the bug?
  4. 4. Which check finds the missing end flag bug in a trie?
  5. 5. insert and search both use this index function with a list of 26 children. ``python def index(ch): return ord(ch) - ord("a") + 1 ` Words like cat and dog work, but zoo raises IndexError: list index out of range`. What is the bug?

5 question(s) left on this page.