Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a character into the Trie node's children.
DSA Python
if char not in node.children: node.children[[1]] = TrieNode()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' or 'children' instead of the character as the key.
Using 'word' which is the whole string, not a single character.
✗ Incorrect
We use 'char' as the key to insert a new TrieNode in the children dictionary.
2fill in blank
mediumComplete the code to move to the next node after inserting or finding the character.
DSA Python
node = node.[1][char]Attempts:
3 left
💡 Hint
Common Mistakes
Using 'keys', 'values', or 'items' which are dictionary methods, not attributes.
✗ Incorrect
We access the 'children' dictionary of the current node to move to the next node.
3fill in blank
hardFix the error in marking the end of a word in the Trie node.
DSA Python
node.[1] = True
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'end' or 'end_of_word' which may not be defined in the TrieNode class.
Using 'is_word' which is not the standard attribute name.
✗ Incorrect
The standard attribute to mark the end of a word is 'is_end' set to True.
4fill in blank
hardFill both blanks to complete the loop that inserts each character of the word into the Trie.
DSA Python
for [1] in [2]: if char not in node.children: node.children[char] = TrieNode()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' or 'children' as loop variables which are not iterable strings.
Using 'char' as the iterable instead of the loop variable.
✗ Incorrect
We loop over each 'char' in the 'word' to insert characters one by one.
5fill in blank
hardFill all three blanks to complete the insert function for the Trie.
DSA Python
def insert(self, [1]): node = self.root for [2] in [3]: if [2] not in node.children: node.children[[2]] = TrieNode() node = node.children[[2]] node.is_end = True
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' as a parameter or loop variable which is incorrect.
Mixing variable names inconsistently.
✗ Incorrect
The function takes 'word', loops over each 'char' in 'word' to insert characters.
