Algorithms and Data Structures · Senior · Question 59 of 75

Which structure would you use for an autocomplete that ranks suggestions by popularity?

Explanation

The trie finds the prefix node in O(length of the prefix); caching the top k per node avoids walking the whole subtree on each keystroke. A plain map can't list words by prefix efficiently.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 59

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz