Algorithms and Data Structures · Middle · Question 35 of 75
What is a trie good for?
- 1Sorting arrays of numbers in O(n) time
- 2Finding the shortest path between two cities
- ✓Correct answer: Prefix lookups, such as autocomplete
Explanation
Each node represents a prefix and its children are the next characters. Checking a prefix costs O(length of the prefix), regardless of how many words are stored.