0
0
DSA C++programming~10 mins

Trie Insert Operation 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 children map of the current Trie node.

DSA C++
current->children['a'] = new TrieNode();
current = current->children[[1]];
Drag options to blanks, or click blank then click option'
A'a'
B'b'
C'c'
D'd'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different character than the one inserted.
Forgetting to move current to the new node.
2fill in blank
medium

Complete the code to check if the current character exists in the children map.

DSA C++
if (current->children.find(word[[1]]) == current->children.end()) {
    current->children[word[i]] = new TrieNode();
}
Drag options to blanks, or click blank then click option'
Aword
B0
Ci
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed index like 0 or 1 instead of the loop variable.
Using the whole word instead of a single character.
3fill in blank
hard

Fix the error in marking the end of a word in the Trie node.

DSA C++
current->[1] = true;
Drag options to blanks, or click blank then click option'
AisEnd
BendOfWord
CisWord
DwordEnd
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not exist in the TrieNode class.
Forgetting to mark the end of the word.
4fill in blank
hard

Fill both blanks to complete the loop that inserts each character of the word into the Trie.

DSA C++
for (int [1] = 0; [2] < word.size(); [2]++) {
    if (current->children.find(word[i]) == current->children.end()) {
        current->children[word[i]] = new TrieNode();
    }
    current = current->children[word[i]];
}
Drag options to blanks, or click blank then click option'
Ai
Bj
Ck
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop declaration and condition.
Using a variable name not used inside the loop body.
5fill in blank
hard

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

DSA C++
void insert(string [1]) {
    TrieNode* current = root;
    for (int i = 0; i < [2].size(); i++) {
        if (current->children.find([3][i]) == current->children.end()) {
            current->children[[3][i]] = new TrieNode();
        }
        current = current->children[[3][i]];
    }
    current->isEnd = true;
}
Drag options to blanks, or click blank then click option'
Aword
Bstr
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inside the function than the parameter.
Forgetting to mark the end of the word.