0
0
DSA C++programming~10 mins

Why Trie Exists and What Hash Map Cannot Do for Strings in DSA C++ - Test Your Knowledge

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'
Aword[i]
Bi
Cnode
Dchildren
Attempts:
3 left
💡 Hint
Common Mistakes
Using the index 'i' instead of the character.
Using the node pointer instead of a character key.
2fill in blank
medium

Complete the code to check if a prefix exists in the Trie.

DSA C++
if (node->children.find([1]) == node->children.end()) return false;
Drag options to blanks, or click blank then click option'
Anode
Bprefix[i]
Ci
Dchildren
Attempts:
3 left
💡 Hint
Common Mistakes
Using the index 'i' instead of the character.
Using the node pointer or children map incorrectly.
3fill in blank
hard

Fix the error in the code to mark the end of a word in the Trie.

DSA C++
node->[1] = true;
Drag options to blanks, or click blank then click option'
Aend
Bchildren
CisWord
DwordEnd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'children' which is a map, not a boolean.
Using 'end' or 'wordEnd' which may not be defined.
4fill in blank
hard

Fill both blanks to complete the Trie search function for a word.

DSA C++
for (int i = 0; i < word.size(); i++) {
    if (node->children.find([1]) == node->children.end()) return false;
    node = node->children[[2]];
}
Drag options to blanks, or click blank then click option'
Aword[i]
Bi
Cnode
Dchildren
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for find and indexing.
Using the index 'i' instead of the character.
5fill in blank
hard

Fill all three blanks to complete the code that builds an unordered_map of words longer than 3 characters to their lengths.

DSA C++
std::unordered_map<std::string, int> lengths;
for (const auto& [3] : words) {
    if ([2] > 3) {
        lengths[[1]] = [2];
    }
}
Drag options to blanks, or click blank then click option'
Aword
Bword.length()
Cwords
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using the collection name instead of the loop variable.
Using the wrong property for length.