2.6 KiB
id | title | description | keywords | sidebar_label | toc_max_heading_level | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
trie | Trie cheatsheet for coding interviews | Trie study guide for coding interviews, including practice questions, techniques, time complexity, and recommended resources |
|
Trie | 2 |
Introduction
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 add
, remove
and search
methods.
Learning resources
- Readings
- Trying to Understand Tries, basecs
- Implement Trie (Prefix Tree), LeetCode
- Additional (only if you have time)
Time complexity
m
is the length of the string used in the operation.
Operation | Big-O | Note |
---|---|---|
Search | O(m) | |
Insert | O(m) | |
Remove | O(m) |
Corner cases
- Searching for a string in an empty trie
- Inserting empty strings into a trie
Techniques
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).
Essential questions
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.
Recommended courses
import AlgorithmCourses from '../_courses/AlgorithmCourses.md'