Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node when the character is not found.
DSA Javascript
if (!node.children.hasOwnProperty(char)) { node.children[char] = [1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an array [] instead of an object {}
Assigning null or empty string instead of an object
✗ Incorrect
We create a new empty object {} to represent the child node for the character.
2fill in blank
mediumComplete the code to move to the next node after inserting or finding the character.
DSA Javascript
node = node.children[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word instead of the character
Using the index instead of the character
✗ Incorrect
We use the current character 'char' to move to the child node.
3fill in blank
hardFix the error in marking the end of a word in the Trie node.
DSA Javascript
node.[1] = true; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent property names like 'wordEnd' or 'endOfWord'
Forgetting to mark the end of the word
✗ Incorrect
The property 'isEnd' is commonly used to mark the end of a word in a Trie node.
4fill in blank
hardFill both blanks to complete the loop that inserts each character of the word into the Trie.
DSA Javascript
for (let [1] = 0; [1] < word.[2]; [1]++) { const char = word[[1]]; // insertion logic }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'j' instead of 'i' for the loop variable
Using 'size' instead of 'length' for string length
✗ Incorrect
We use 'i' as the loop variable and 'length' to get the word's length.
5fill in blank
hardFill all three blanks to complete the insert function for the Trie.
DSA Javascript
insert(word) {
let node = this.root;
for (let [1] = 0; [1] < word.[2]; [1]++) {
const char = word[[1]];
if (!node.children.hasOwnProperty(char)) {
node.children[char] = [3];
}
node = node.children[char];
}
node.isEnd = true;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'null' instead of '{}'
Using wrong loop variable or property for length
✗ Incorrect
We use 'i' as the loop index, 'length' for word length, and '{}' to create a new child node.