0
0
DSA Typescriptprogramming~10 mins

Trie Insert 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 add a character node to the children map.

DSA Typescript
if (!node.children.has(char)) {
  node.children.[1](char, new TrieNode());
}
Drag options to blanks, or click blank then click option'
Aset
Badd
Cpush
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using array methods like push instead of Map methods.
Trying to use add which is for Set, not Map.
2fill in blank
medium

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

DSA Typescript
node = node.children.[1](char)!;
Drag options to blanks, or click blank then click option'
Adelete
Bset
Chas
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using set instead of get, which would overwrite the node.
Using has which returns a boolean, not the node.
3fill in blank
hard

Fix the error in marking the end of a word in the Trie node.

DSA Typescript
node.[1] = true;
Drag options to blanks, or click blank then click option'
AwordEnd
BisEnd
CendOfWord
DisWord
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent property names that do not exist in the TrieNode class.
Using properties that are not boolean flags.
4fill in blank
hard

Fill both blanks to complete the loop that inserts each character of the word.

DSA Typescript
for (const [1] of word) {
  if (!node.children.[2]([1])) {
    node.children.set([1], new TrieNode());
  }
  node = node.children.get([1])!;
}
Drag options to blanks, or click blank then click option'
Achar
Bletter
Chas
Dincludes
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'includes' which is an array or string method, not Map.
Using 'letter' as loop variable but 'has' is the correct Map method.
5fill in blank
hard

Fill all three blanks to complete the insert method for the Trie.

DSA Typescript
insert(word: string): void {
  let node = this.root;
  for (const [1] of word) {
    if (!node.children.[2]([1])) {
      node.children.set([1], new TrieNode());
    }
    node = node.children.get([1])!;
  }
  node.[3] = true;
}
Drag options to blanks, or click blank then click option'
Achar
Bhas
CisEnd
Dletter
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names for the end of word flag.
Using string methods instead of Map methods for children.