Recall & Review
beginner
What does 'Count Words with Given Prefix' mean in simple terms?
It means finding how many words in a list start with the same beginning letters (prefix). For example, counting words starting with "pre" in ["prefix", "prevent", "apple"] gives 2.
Click to reveal answer
intermediate
Why is a Trie (prefix tree) useful for counting words with a given prefix?
A Trie stores words so that common beginnings share nodes. This makes it fast to find all words starting with a prefix by just following the prefix path and counting words below it.
Click to reveal answer
intermediate
In Go, what basic steps do you take to count words with a given prefix using a Trie?
1. Build a Trie by inserting all words.<br>2. Traverse the Trie following the prefix letters.<br>3. Count how many words are stored under that prefix node.
Click to reveal answer
advanced
What is the time complexity benefit of using a Trie for prefix counting compared to checking each word?
Using a Trie, counting words with a prefix takes time proportional to the prefix length, not the total number of words. Checking each word takes time proportional to all words times prefix length.
Click to reveal answer
beginner
What happens if the prefix does not exist in the Trie?
If the prefix path is missing in the Trie, it means no words start with that prefix, so the count is zero.
Click to reveal answer
What data structure is best suited for counting words with a given prefix efficiently?
✗ Incorrect
Trie stores words by prefixes, making prefix queries fast.
If you have 1000 words and want to count words starting with "go", what is the fastest approach?
✗ Incorrect
Trie allows direct prefix traversal, faster than checking all words.
What does the prefix "pre" mean when counting words?
✗ Incorrect
Prefix means the start of the word.
What is the count of words with prefix "cat" in ["cat", "cater", "dog", "catalog"]?
✗ Incorrect
"cat", "cater", and "catalog" all start with "cat".
If a prefix is not found in the Trie, what should the count be?
✗ Incorrect
No words start with that prefix, so count is zero.
Explain how a Trie helps count words with a given prefix quickly.
Think about how words with the same start share parts.
You got /4 concepts.
Describe the steps to count words with a given prefix using Go code and a Trie.
Focus on building and searching the Trie.
You got /4 concepts.