Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current character exists in the children map.
DSA C++
if (node->children.find(word[[1]]) == node->children.end()) { return false; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word instead of an index.
Using a variable not defined in the loop.
✗ Incorrect
We use 'i' as the index to access each character in the word during traversal.
2fill in blank
mediumComplete the code to move to the next node in the trie for the current character.
DSA C++
node = node->children[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the index 'i' directly instead of the character.
Using 'node' or 'children' which are not keys.
✗ Incorrect
We use word[i] to get the current character and move to its child node.
3fill in blank
hardFix the error in the return statement to check if the word ends at this node.
DSA C++
return node->[1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect flag names like 'isWord' or 'endOfWord'.
Forgetting to check this flag.
✗ Incorrect
The boolean flag 'isEnd' indicates if the node marks the end of a word.
4fill in blank
hardFill both blanks to complete the for loop that iterates over each character in the word.
DSA C++
for (int [1] = 0; [2] < word.size(); ++[1]) { // loop body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop condition and increment.
Using a variable not declared.
✗ Incorrect
The loop variable 'i' is used consistently to iterate over the word characters.
5fill in blank
hardFill all three blanks to complete the search function that returns true if the word exists in the trie.
DSA C++
bool search(string word) {
TrieNode* node = root;
for (int [1] = 0; [2] < word.size(); ++[1]) {
if (node->children.find(word[[3]]) == node->children.end()) {
return false;
}
node = node->children[word[[3]]];
}
return node->isEnd;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for loop and indexing.
Using a constant index instead of the loop variable.
✗ Incorrect
The loop variable 'i' is used consistently to index characters in the word during traversal.