0
0
DSA Goprogramming~10 mins

Trie Node Design and Initialization in DSA Go - 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 struct with a children map.

DSA Go
type TrieNode struct {
    children map[rune]*[1]
    isEnd bool
}
Drag options to blanks, or click blank then click option'
ANode
BTrieNode
CTreeNode
DTrie
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different struct name for children map values.
Not using pointers for child nodes.
2fill in blank
medium

Complete the code to initialize a new TrieNode with an empty children map.

DSA Go
func NewTrieNode() *TrieNode {
    return &TrieNode{
        children: make(map[rune]*[1]),
        isEnd: false,
    }
}
Drag options to blanks, or click blank then click option'
ATrie
BNode
CTreeNode
DTrieNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using make with wrong type.
Not initializing the map, causing nil map errors.
3fill in blank
hard

Fix the error in the code to add a child node for a character key.

DSA Go
func (node *TrieNode) AddChild(ch rune) {
    if node.children == nil {
        node.children = make(map[rune]*[1])
    }
    node.children[ch] = NewTrieNode()
}
Drag options to blanks, or click blank then click option'
ATrieNode
BNode
CTreeNode
DTrie
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect struct name in map initialization.
Not initializing the map before adding children.
4fill in blank
hard

Fill both blanks to check if a child node exists and return it.

DSA Go
func (node *TrieNode) GetChild(ch rune) (*TrieNode, bool) {
    child, [1] := node.children[ch]
    return child, [2]
}
Drag options to blanks, or click blank then click option'
Aok
Bexists
Cfound
Dpresent
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names other than 'ok' for the comma-ok idiom.
Returning the wrong variable for existence check.
5fill in blank
hard

Fill all three blanks to insert a word into the trie.

DSA Go
func (node *TrieNode) Insert(word string) {
    current := node
    for _, ch := range word {
        child, [1] := current.children[ch]
        if ![2] {
            child = NewTrieNode()
            current.children[ch] = [3]
        }
        current = child
    }
    current.isEnd = true
}
Drag options to blanks, or click blank then click option'
Aok
Bexists
Cchild
Dpresent
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for existence check.
Not assigning the new node to the children map.