Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The English lowercase alphabet has 26 letters, so the children array size must be 26.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEndOfWord to true by mistake.
Using NULL or 0 which are not boolean values.
✗ Incorrect
When a TrieNode is created, it should not mark the end of a word, so isEndOfWord is false.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 25 which misses the last child pointer.
Using children.size() which is not valid for raw arrays.
✗ Incorrect
The loop must run 26 times to cover all children pointers for letters 'a' to 'z'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of nullptr (older style).
Initializing with new TrieNode() instead of nullptr.
✗ Incorrect
We declare a pointer named root and initialize it to nullptr to indicate it points to nothing initially.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEndOfWord to true by mistake.
Using wrong number for children count.
Not creating a new TrieNode object.
✗ Incorrect
We create a new TrieNode object, set isEndOfWord to false, and initialize all 26 children pointers to nullptr.