0
0
DSA C++programming~5 mins

Prefix Search Using Trie in DSA C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AA character of a string
BA whole word
CAn integer value
DA prefix length
What is the main advantage of using a Trie for prefix search?
ASorts words alphabetically
BFaster search by following character paths
CStores only numbers
DUses less memory than arrays
What does the 'isEndOfWord' flag indicate in a Trie node?
ANode has no children
BNode is the root of the Trie
CNode is the last character of a stored word
DNode stores a prefix length
If a prefix is not found in a Trie, what happens?
ASearch stops early, no words with that prefix
BAll words are returned
CTrie deletes the prefix
DSearch continues to the end
What is the time complexity of prefix search in a Trie for prefix length m?
AO(m * n)
BO(n)
CO(log n)
DO(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.