0
0
DSA Javascriptprogramming~10 mins

Trie Node Design and Initialization 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 initialize a TrieNode with an empty children object.

DSA Javascript
class TrieNode {
  constructor() {
    this.children = [1];
    this.isEndOfWord = false;
  }
}
Drag options to blanks, or click blank then click option'
Anull
B[]
C{}
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using an array [] instead of an object for children.
Setting children to null or empty string.
2fill in blank
medium

Complete the code to mark the node as the end of a word.

DSA Javascript
class TrieNode {
  constructor() {
    this.children = {};
    this.isEndOfWord = [1];
  }
}
Drag options to blanks, or click blank then click option'
Anull
Bfalse
Ctrue
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEndOfWord to true by default.
Using null or undefined instead of a boolean.
3fill in blank
hard

Fix the error in the constructor to properly initialize children as an empty object.

DSA Javascript
class TrieNode {
  constructor() {
    this.children = new [1]();
    this.isEndOfWord = false;
  }
}
Drag options to blanks, or click blank then click option'
AArray
BSet
CMap
DObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using Array or Set which are not suitable for key-value pairs.
Using Map which requires different syntax.
4fill in blank
hard

Fill both blanks to complete the method that adds a child node for a character.

DSA Javascript
addChild(char) {
  if (!this.children.hasOwnProperty([1])) {
    this.children[[2]] = new TrieNode();
  }
}
Drag options to blanks, or click blank then click option'
A'char'
Bchar
C"char"
Dthis.char
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals like 'char' or "char" instead of the variable.
Using this.char which is undefined.
5fill in blank
hard

Fill all three blanks to complete the method that checks if a child node exists for a character.

DSA Javascript
hasChild([1]) {
  return this.children.hasOwnProperty([2]) && this.children[[3]] !== undefined;
}
Drag options to blanks, or click blank then click option'
Achar
B'char'
Cchar.toLowerCase()
Dthis.char
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals instead of the variable.
Using this.char which is not defined.