0
0
DSA Typescriptprogramming~10 mins

Trie Search Operation in DSA Typescript - 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 of the node.

DSA Typescript
if (!node.children.has([1])) {
    return false;
}
Drag options to blanks, or click blank then click option'
Aindex
Bchar
Cword
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word instead of a single character.
Using the node variable instead of the character.
2fill in blank
medium

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

DSA Typescript
node = node.children.get([1])!;
Drag options to blanks, or click blank then click option'
Achar
Bindex
Cword
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word or index instead of the character.
Trying to get children with the node variable.
3fill in blank
hard

Fix the error in the return statement to check if the node marks the end of a word.

DSA Typescript
return node.[1];
Drag options to blanks, or click blank then click option'
AisWord
Bend
CisEndOfWord
DwordEnd
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like 'isWord' or 'end'.
Returning the node itself instead of a boolean.
4fill in blank
hard

Fill both blanks to iterate over each character in the word and check the trie.

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

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

DSA Typescript
function search(word: string): boolean {
    let node = this.root;
    for (let i = 0; i < word.length; i++) {
        const char = word[[1]];
        if (!node.children.has([2])) {
            return false;
        }
        node = node.children.get([3])!;
    }
    return node.isEndOfWord;
}
Drag options to blanks, or click blank then click option'
Ai
Bchar
Cword
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'char' to check children.
Using 'i' instead of 'char' to get children.