Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current character exists in the children of the trie node.
DSA C
if (node->children[[1]] == NULL) { return 0; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using the character directly as index causes out-of-bound errors.
Using 'i' as index instead of character index.
✗ Incorrect
We subtract 'a' from the character to get the index in the children array (0-25).
2fill in blank
mediumComplete the code to move to the next node in the trie for the current character.
DSA C
node = node->children[[1]];Attempts:
3 left
💡 Hint
Common Mistakes
Using the character directly instead of index.
Using loop index 'i' instead of character index.
✗ Incorrect
We move to the child node corresponding to the current character index.
3fill in blank
hardFix the error in the return statement to correctly check if the word ends here.
DSA C
return node->[1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect field names causes compilation errors.
Confusing the flag name with similar variants.
✗ Incorrect
The correct field name to check if a node marks the end of a word is 'isEndOfWord'.
4fill in blank
hardFill both blanks to complete the loop that iterates over each character of the word.
DSA C
for (int [1] = 0; [2] < length; [1]++) { // loop body }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables in loop condition and increment.
Using variable names that do not match the loop initialization.
✗ Incorrect
The loop variable 'i' is used consistently to iterate from 0 to length-1.
5fill in blank
hardFill all three blanks to complete the search function that returns 1 if word is found, else 0.
DSA C
int search(struct TrieNode* root, const char* word) {
struct TrieNode* node = root;
int length = strlen(word);
for (int [1] = 0; [1] < [2]; [1]++) {
if (node->children[word[[1]] - 'a'] == NULL) {
return 0;
}
node = node->children[word[[1]] - 'a'];
}
return node->isEndOfWord;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop variable or limit causes incorrect iteration.
Accessing characters with wrong index variable.
✗ Incorrect
The loop uses 'i' to iterate from 0 to length-1, and accesses characters with word[i].
