0
0
DSA Typescriptprogramming~10 mins

Trie Node Design and Initialization 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 declare a TrieNode class with a children map.

DSA Typescript
class TrieNode {
  children: Map<string, TrieNode> = new Map();
  isEndOfWord: boolean = false;

  constructor() {
    this.children = new [1]();
  }
}
Drag options to blanks, or click blank then click option'
ASet
BMap
CArray
DObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using Array instead of Map for children.
Using Set which does not store key-value pairs.
2fill in blank
medium

Complete the code to add a child node for a given character in the TrieNode.

DSA Typescript
addChild(char: string) {
  if (!this.children.has(char)) {
    this.children.set(char, new [1]());
  }
}
Drag options to blanks, or click blank then click option'
AMap
BNode
CTrieNode
DSet
Attempts:
3 left
💡 Hint
Common Mistakes
Using Map or Set instead of TrieNode for child nodes.
Using an undefined class name like Node.
3fill in blank
hard

Fix the error in the constructor to initialize isEndOfWord correctly.

DSA Typescript
constructor() {
  this.children = new Map();
  this.isEndOfWord = [1];
}
Drag options to blanks, or click blank then click option'
Afalse
Btrue
Cnull
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEndOfWord to true by default.
Using null or undefined which are not booleans.
4fill in blank
hard

Fill both blanks to check if a character exists and retrieve its child node.

DSA Typescript
getChild(char: string): TrieNode | undefined {
  if (this.children.[1](char)) {
    return this.children.[2](char);
  }
  return undefined;
}
Drag options to blanks, or click blank then click option'
Ahas
Bget
Cset
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using set() instead of get() to retrieve a value.
Using delete() which removes a key.
5fill in blank
hard

Fill all three blanks to implement a method that marks the node as end of a word and adds a child if missing.

DSA Typescript
markEndAndAddChild(char: string) {
  this.isEndOfWord = [1];
  if (!this.children.[2](char)) {
    this.children.[3](char, new TrieNode());
  }
}
Drag options to blanks, or click blank then click option'
Atrue
Bhas
Cset
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEndOfWord to false instead of true.
Using get() instead of has() to check existence.
Using delete() instead of set() to add child.