0
0
Data Structures Theoryknowledge~10 mins

Trie insertion and search in Data Structures Theory - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to insert a character into the Trie node's children.

Data Structures Theory
node.children[[1]] = TrieNode()
Drag options to blanks, or click blank then click option'
Aword
Bchar
Cindex
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word or index instead of the character as the key.
2fill in blank
medium

Complete the code to check if a character exists in the current Trie node's children during search.

Data Structures Theory
if [1] in node.children:
Drag options to blanks, or click blank then click option'
Aword
Bnode
Cchar
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for the whole word or index instead of the character.
3fill in blank
hard

Fix the error in the code that marks the end of a word in the Trie after insertion.

Data Structures Theory
node.[1] = True
Drag options to blanks, or click blank then click option'
Ais_end_of_word
Bend
Cis_word
Dword_end
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like 'end' or 'word_end' which are not standard.
4fill in blank
hard

Fill both blanks to complete the dictionary comprehension that creates a mapping of characters to Trie nodes for a given word.

Data Structures Theory
{ [1]: TrieNode() for [2] in word }
Drag options to blanks, or click blank then click option'
Achar
Bnode
Cletter
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' or 'word' as keys or loop variables which are incorrect.
5fill in blank
hard

Fill all three blanks to complete the search function that returns True if the word exists in the Trie.

Data Structures Theory
def search(word):
    node = root
    for [1] in word:
        if [2] not in node.children:
            return False
        node = node.children[[3]]
    return node.is_end_of_word
Drag options to blanks, or click blank then click option'
Achar
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names or the whole word instead of characters.