Tries (Prefix Trees) Quiz
40 comprehensive questions exploring trie data structures — with 16 code examples covering trie insertion, search operations, prefix queries, and memory optimization techniques in this cpp quiz.
Question 1
What is a trie data structure?
Question 2
In a trie, what does each node typically contain?
Trie node: children array/map, endOfWord flag
Children indexed by characterQuestion 3
What is the time complexity of trie search?
Question 4
How does trie insertion work?
Insert word: traverse/create nodes for each char
Mark last node as endOfWordQuestion 5
What is the advantage of tries over hash tables for string operations?
Question 6
How does trie prefix search work?
Prefix search: find node for prefix
Then traverse subtree for completionsQuestion 7
What is the space complexity of a trie?
Question 8
How is a trie typically implemented?
struct TrieNode {
TrieNode* children[26];
bool isEndOfWord;
};Question 9
What is the worst-case time complexity for trie insertion?
Question 10
In trie applications, what is autocomplete functionality?
Autocomplete: find prefix node
DFS/BFS subtree for word completionsQuestion 11
What is the trie property that enables prefix operations?
Question 12
How does trie handle case sensitivity?
Case sensitive: 'A' != 'a' different children
Case insensitive: normalize to lower/upperQuestion 13
What is the memory issue with standard trie implementations?
Question 14
How can tries be memory-optimized?
Use map instead of array: only store used children
Compress chains of single-child nodesQuestion 15
What is the significance of the endOfWord flag in tries?
Question 16
How does trie support dictionary operations?
Dictionary: insert all words
Search: traverse and check endOfWord
Prefix: find node, count subtree wordsQuestion 17
What is the advantage of tries in IP routing?
Question 18
How does trie handle deletion operations?
Delete: find word, unset endOfWord
Remove nodes if no children and not endOfWordQuestion 19
What is the cache performance of trie operations?
Question 20
In trie applications, what is spell checking?
Spell check: search word in trie
If not found, suggest similar wordsQuestion 21
What is the trie structure advantage over binary search trees for strings?
Question 22
How does trie support counting words with a prefix?
Prefix count: find prefix node
Count endOfWord flags in subtreeQuestion 23
What is the issue with large alphabets in tries?
Question 24
How does trie enable lexicographical ordering?
Lex order: inorder traversal of trie
Visit children in character orderQuestion 25
What is path compression in tries?
Question 26
In trie applications, what is the significance of the root node?
Root: empty string, start of all words
No character stored at rootQuestion 27
How does trie support wildcard searches?
Question 28
What is the practical memory usage of tries vs hash sets for strings?
Trie: O(total chars) shared prefixes
Hash set: O(total chars) no sharingQuestion 29
How does trie handle non-English alphabets?
Question 30
What is the trie advantage in mobile text input?
Mobile: prefix matching for suggestions
T9-style predictive textQuestion 31
What is the significance of tries in algorithm design?
Question 32
How does trie compare to ternary search trees?
Trie: one child per char
TST: three children (left, mid, right)Question 33
What is the trie limitation for very long strings?
Question 34
How does trie support longest common prefix operations?
LCP: traverse until paths diverge
Count matching charactersQuestion 35
What is the cache-friendly optimization for tries?
Question 36
In trie applications, what is the significance of endOfWord flags?
endOfWord: allows multiple words per path
'car' and 'card' both validQuestion 37
How does trie handle reverse lookups?
Question 38
What is the practical implementation choice for trie children?
Small alphabet: array[26]
Large alphabet: unordered_map<char, Node*>Question 39
How does trie support approximate string matching?
Question 40
Considering trie data structures and their applications in string processing, which fundamental property makes tries essential for efficient prefix-based operations despite potential memory overhead?
