0
0
DSA C++programming~10 mins

Trie Node Design and Initialization 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 declare a pointer array for 26 lowercase English letters in the TrieNode class.

DSA C++
class TrieNode {
public:
    TrieNode* children[[1]];
    bool isEndOfWord;
    TrieNode() {
        isEndOfWord = false;
        for (int i = 0; i < [1]; i++) {
            children[i] = nullptr;
        }
    }
};
Drag options to blanks, or click blank then click option'
A26
B25
C52
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 25 instead of 26, which misses one letter.
Using 52 which is for uppercase and lowercase combined, but here only lowercase is needed.
2fill in blank
medium

Complete the constructor to initialize the isEndOfWord flag to false.

DSA C++
TrieNode() {
    isEndOfWord = [1];
    for (int i = 0; i < 26; i++) {
        children[i] = nullptr;
    }
}
Drag options to blanks, or click blank then click option'
Afalse
Btrue
CNULL
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEndOfWord to true by mistake.
Using NULL or 0 which are not boolean values.
3fill in blank
hard

Fix the error in the loop that initializes children pointers to nullptr.

DSA C++
for (int i = 0; i < [1]; i++) {
    children[i] = nullptr;
}
Drag options to blanks, or click blank then click option'
ANULL
B26
Cchildren.size()
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Using 25 which misses the last child pointer.
Using children.size() which is not valid for raw arrays.
4fill in blank
hard

Fill both blanks to declare a TrieNode pointer and initialize it to nullptr.

DSA C++
TrieNode* [1] = [2];
Drag options to blanks, or click blank then click option'
Aroot
Bnullptr
CNULL
Dnew TrieNode()
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of nullptr (older style).
Initializing with new TrieNode() instead of nullptr.
5fill in blank
hard

Fill all three blanks to create a new TrieNode and assign it to root, then mark it as not end of word.

DSA C++
root = [1];
root->isEndOfWord = [2];
for (int i = 0; i < [3]; i++) {
    root->children[i] = nullptr;
}
Drag options to blanks, or click blank then click option'
Anew TrieNode()
Bfalse
C26
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEndOfWord to true by mistake.
Using wrong number for children count.
Not creating a new TrieNode object.