Recall & Review
beginner
What is a Trie data structure?
A Trie is a tree-like data structure used to store a dynamic set of strings where keys are usually strings. Each node represents a character, and paths from the root to nodes represent prefixes of stored words.
Click to reveal answer
beginner
How does a Trie help in prefix search?
A Trie allows quick prefix search by following the path of characters from the root node. If the prefix exists, the search reaches the node representing the last character of the prefix, enabling retrieval of all words starting with that prefix.
Click to reveal answer
intermediate
What is the time complexity of searching a prefix in a Trie?
The time complexity is O(m), where m is the length of the prefix. This is because the search follows the path character by character without scanning all stored words.
Click to reveal answer
beginner
Explain the role of the 'isEndOfWord' flag in a Trie node.
The 'isEndOfWord' flag marks if a node corresponds to the last character of a valid word stored in the Trie. It helps distinguish between prefixes and complete words during search and retrieval.
Click to reveal answer
beginner
What happens if a prefix is not found in a Trie during search?
If the prefix path does not exist in the Trie, the search stops early, indicating no words start with that prefix. This makes prefix search efficient by avoiding unnecessary checks.
Click to reveal answer
What does each node in a Trie represent?
✗ Incorrect
Each node in a Trie represents a single character of the stored strings.
What is the main advantage of using a Trie for prefix search?
✗ Incorrect
Trie allows fast prefix search by following the path of characters without scanning all words.
What does the 'isEndOfWord' flag indicate in a Trie node?
✗ Incorrect
'isEndOfWord' marks the end of a valid word in the Trie.
If a prefix is not found in a Trie, what happens?
✗ Incorrect
Search stops early if prefix path does not exist, indicating no matching words.
What is the time complexity of prefix search in a Trie for prefix length m?
✗ Incorrect
Prefix search time depends only on prefix length m, so it is O(m).
Describe how a Trie is used to perform prefix search.
Think about how you follow letters step-by-step in a tree.
You got /5 concepts.
Explain why prefix search in a Trie is efficient compared to scanning all words.
Consider how you find words starting with 'app' without checking every word.
You got /4 concepts.