0
0
DSA Javascriptprogramming~10 mins

Trie Search Operation in DSA Javascript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the current character exists in the children nodes.

DSA Javascript
if (!node.children.hasOwnProperty([1])) {
  return false;
}
Drag options to blanks, or click blank then click option'
Achar
Bnode
Cindex
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word instead of the current character.
Using the node object instead of the character key.
2fill in blank
medium

Complete the code to move to the next node in the Trie for the current character.

DSA Javascript
node = node.children[[1]];
Drag options to blanks, or click blank then click option'
Aword
Bchar
Cindex
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word or index instead of the character.
Trying to assign node to itself.
3fill in blank
hard

Fix the error in the return statement to correctly check if the word ends here.

DSA Javascript
return node.[1] === true;
Drag options to blanks, or click blank then click option'
AisEndOfWord
Bend
CisWord
DwordEnd
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like isWord or end.
Checking the property incorrectly without === true.
4fill in blank
hard

Fill both blanks to complete the loop that iterates over each character in the word.

DSA Javascript
for (let [1] = 0; [2] < word.length; [1]++) {
  const char = word[[1]];
  // rest of the code
}
Drag options to blanks, or click blank then click option'
Ai
Bj
Ck
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables in the loop condition and increment.
Using variable names that are not consistent.
5fill in blank
hard

Fill all three blanks to complete the search function that returns true if the word exists in the Trie.

DSA Javascript
function search(word) {
  let node = this.root;
  for (let i = 0; i < word.length; i++) {
    const [1] = word[i];
    if (!node.children.hasOwnProperty([2])) {
      return false;
    }
    node = node.children[[3]];
  }
  return node.isEndOfWord === true;
}
Drag options to blanks, or click blank then click option'
Achar
Bword
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for the character in different places.
Checking children with the whole word instead of the character.