Trie cheatsheet for coding interviews
Tries are special trees (prefix trees) that make searching and storing strings more efficient. Tries have many practical applications, such as conducting searches and providing autocomplete. It is helpful to know these common applications so that you can easily identify when a problem can be efficiently solved using a trie.
Be familiar with implementing from scratch, a
Trie class and its
- Trying to Understand Tries, basecs
- Implement Trie (Prefix Tree), LeetCode
- Additional (only if you have time)
m is the length of the string used in the operation.
- Searching for a string in an empty trie
- Inserting empty strings into a trie
Sometimes preprocessing a dictionary of words (given in a list) into a trie, will improve the efficiency of searching for a word of length k, among n words. Searching becomes O(k) instead of O(n).
These are essential questions to practice if you're studying for this topic.
Recommended practice questions
These are recommended questions to practice after you have studied for the topic and have practiced the essential questions.
AlgoMonster aims to help you ace the technical interview in the shortest time possible. By Google engineers, AlgoMonster uses a data-driven approach to teach you the most useful key question patterns and has contents to help you quickly revise basic data structures and algorithms. Best of all, AlgoMonster is not subscription-based - pay a one-time fee and get lifetime access. Join today for a 70% discount →
Grokking the Coding Interview: Patterns for Coding Questions
Master the Coding Interview: Data Structures + Algorithms