Recall & Review
beginner
What is a Trie data structure?
A Trie is a tree-like data structure that stores a dynamic set of strings, where each node represents a character. It is used for efficient retrieval of words, especially for prefix-based searches.
Click to reveal answer
intermediate
How does a Trie help in finding the longest word in a dictionary?
By inserting all words into a Trie, we can traverse nodes only if they mark the end of a valid word. This ensures that prefixes are valid words, helping us find the longest word built one character at a time.
Click to reveal answer
beginner
What condition must be true for a node to be considered during traversal when finding the longest word?
The node must mark the end of a word (isEnd = true) to ensure the prefix up to that node is a valid word.
Click to reveal answer
intermediate
Why do we prefer lexicographical order when multiple longest words exist?
Choosing the lexicographically smallest word ensures a consistent and predictable result when multiple words have the same maximum length.
Click to reveal answer
intermediate
What is the time complexity of building a Trie with n words of average length m?
The time complexity is O(n * m), since each character of every word is inserted once.
Click to reveal answer
What does each node in a Trie represent?
✗ Incorrect
Each node in a Trie represents a single character of a word.
When finding the longest word in a Trie, which nodes do we consider for traversal?
✗ Incorrect
We only traverse nodes that mark the end of a valid word to ensure prefixes are valid.
If two words have the same length, which one is chosen as the longest word?
✗ Incorrect
The lexicographically smaller word is chosen for consistency.
What is the main advantage of using a Trie for prefix-based searches?
✗ Incorrect
Trie allows fast retrieval of words sharing common prefixes.
What is the time complexity to insert one word of length m into a Trie?
✗ Incorrect
Inserting a word requires processing each character once, so O(m).
Explain how a Trie is used to find the longest word in a dictionary where every prefix is also a valid word.
Think about how prefixes relate to valid words in the Trie.
You got /4 concepts.
Describe the steps to build a Trie and how to traverse it to find the longest word with all prefixes valid.
Focus on insertion and traversal rules.
You got /4 concepts.