0
0
DSA Goprogramming~10 mins

Trie Insert Operation 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 create a new Trie node.

DSA Go
func newNode() *TrieNode {
    return &TrieNode{
        children: make(map[rune]*TrieNode),
        isEnd: [1],
    }
}
Drag options to blanks, or click blank then click option'
Afalse
Bnil
Ctrue
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEnd to true for new nodes.
Using nil or 0 instead of a boolean value.
2fill in blank
medium

Complete the code to check if a child node exists for a character.

DSA Go
if _, ok := current.children[[1]]; !ok {
    current.children[[1]] = newNode()
}
Drag options to blanks, or click blank then click option'
Aletter
Bword[i]
Crune
Dchar
Attempts:
3 left
💡 Hint
Common Mistakes
Using an undefined variable like 'rune' or 'letter'.
Using word[i] which is a byte, not rune.
3fill in blank
hard

Fix the error in marking the end of a word in the insert function.

DSA Go
current.[1] = true
Drag options to blanks, or click blank then click option'
Aend
BisEnd
CisWord
DwordEnd
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect field names like 'end' or 'wordEnd'.
Forgetting to mark the end of the word.
4fill in blank
hard

Fill both blanks to complete the loop that inserts characters into the Trie.

DSA Go
for _, [1] := range [2] {
    if _, ok := current.children[char]; !ok {
        current.children[char] = newNode()
    }
    current = current.children[char]
}
Drag options to blanks, or click blank then click option'
Achar
Bword
Cletter
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variable names.
Mixing up the order of blanks.
5fill in blank
hard

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

DSA Go
func (t *Trie) Insert([1] string) {
    current := t.root
    for _, [2] := range [1] {
        if _, ok := current.children[[2]]; !ok {
            current.children[[2]] = newNode()
        }
        current = current.children[[2]]
    }
    current.isEnd = true
}
Drag options to blanks, or click blank then click option'
Aword
Bchar
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not matching loop variable with map key.