0
0
Data Structures Theoryknowledge~10 mins

Prefix matching with tries 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 word into a trie node.

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

Complete the code to check if a prefix exists in the trie.

Data Structures Theory
if [1] not in node.children:
    return False
Drag options to blanks, or click blank then click option'
Aprefix
Bword
Cchar
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for the whole prefix string instead of one character.
Using the node variable instead of the character.
3fill in blank
hard

Fix the error in the code to move to the next node during prefix search.

Data Structures Theory
node = node.children[[1]]
Drag options to blanks, or click blank then click option'
Achar
Bprefix
Cword
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using the entire prefix string as a key.
Using an index number instead of the character.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length if the word starts with 'pre'.

Data Structures Theory
{word: [1] for word in words if word.[2]('pre')}
Drag options to blanks, or click blank then click option'
Alen(word)
Bstartswith
C==
Din
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'startswith' to check prefix.
Using 'in' which checks substring anywhere, not just prefix.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if the length is greater than 3.

Data Structures Theory
{ [1]: [2] for [3] in words if len(word) > 3 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Cword
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of uppercase.
Using the wrong variable name in the comprehension.