0
0
DSA C++programming~10 mins

Word Search in Trie in DSA C++ - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to insert a character into the Trie node's children.

DSA C++
node->children[[1]] = new TrieNode();
Drag options to blanks, or click blank then click option'
A'c' - 'a'
B'b' - 'a'
C'z' - 'a'
D'a' - 'a'
Attempts:
3 left
💡 Hint
Common Mistakes
Using character directly without subtracting 'a'.
Using wrong character subtraction causing out of range index.
2fill in blank
medium

Complete the code to check if the current Trie node marks the end of a word.

DSA C++
if (node->[1]) { return true; }
Drag options to blanks, or click blank then click option'
AwordEnd
BendOfWord
CisEnd
DisWord
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect or undefined flag names.
Checking for null pointer instead of boolean flag.
3fill in blank
hard

Fix the error in the search function to correctly traverse the Trie for each character.

DSA C++
node = node->children[[1]];
Drag options to blanks, or click blank then click option'
Aword[i] - 'a'
Bword[i]
Ci
D'a'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the character directly as index causing out of bounds.
Using the loop index 'i' as index instead of character mapping.
4fill in blank
hard

Fill both blanks to complete the recursive helper function for word search in Trie.

DSA C++
bool searchHelper(TrieNode* node, const string& word, int [1]) {
    if ([2] == word.size()) return node->isEnd;
    int index = word[[1]] - 'a';
    if (!node->children[index]) return false;
    return searchHelper(node->children[index], word, [1] + 1);
}
Drag options to blanks, or click blank then click option'
Apos
Bindex
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing mismatch.
Comparing wrong variable to word size.
5fill in blank
hard

Fill all three blanks to complete the insert function for adding a word to the Trie.

DSA C++
void insert(string word) {
    TrieNode* node = root;
    for (int [1] = 0; [2] < word.size(); [3]++) {
        int index = word[[2]] - 'a';
        if (!node->children[index]) {
            node->children[index] = new TrieNode();
        }
        node = node->children[index];
    }
    node->isEnd = true;
}
Drag options to blanks, or click blank then click option'
Ai
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in loop causing errors.
Incorrect loop increment syntax.