Tags

Trie / Prefix Tree

Trie / Prefix Tree

1 lesson
3 problems
2 code snippets
1 question bank
1 system design
3 community items

trie

Data Structures

1 lesson

Trie (Prefix Tree)

Intermediate

55 min

2 prereqs

Type the letters `a-p-p` into a search box and the autocomplete dropdown produces `apple`, `application`, `apply`, and `appoint` before you finish the next keystroke. The data structure doing that work is a **Trie** (or prefix tree), where every stored word is a path from root to a marked node and every shared prefix is shared in memory exactly once. This lesson covers the trie node layout (a `children` map plus an `isEndOfWord` flag), `insert`, `search`, and `startsWith` operations that all run in `O(m)` for a query of length `m` (independent of how many words the trie holds), and a `delete` that has to be careful not to break paths used by other words. You will also analyze the space behavior, including when a trie wins over a hash set (prefix queries, lexicographic enumeration) and when it loses (memory-tight workloads with no prefix structure to exploit). In **Hash Map (Dictionary) Basics**, you used hashing to answer 'have I seen this exact key' in `O(1)`; a trie answers a strictly richer question (any prefix lookup) by trading `O(1)` exact-match for `O(m)` traversal. **Trees: Binary Tree Fundamentals** introduced the recursive child-pointer pattern, and a trie generalizes it from two children per node to one child per alphabet symbol. With a trie in your toolkit, the curriculum moves on to graph and hash extensions that solve a different family of problems built on the same node-and-edge thinking.

Not Started

0%

Trie / Prefix Tree
Trie Operations
Trees
Data Structures
Strings
Searching
Hash Map / Dictionary
Intermediate
Premium

Practice Problems

3 problems

Word Search II

Not Started
Hard

Given a 2D board of characters and a list of words, find all words that can be formed by sequentially adjacent cells on the board, using each cell at most once per word.

Trie / Prefix Tree
Trie Operations
Backtracking
DFS
Arrays
Strings
Advanced

1.1k

38

Design Add and Search Words

Not Started
Medium

Design a data structure that supports adding words and searching for words with wildcard characters, where '.' can match any single letter.

Trie / Prefix Tree
Trie Operations
DFS
Design Patterns
Strings
Intermediate

1k

14

Implement Trie (Prefix Tree)

Free
Not Started
Medium

Implement a trie (prefix tree) that supports inserting words, searching for exact words, and checking if any word starts with a given prefix.

Trie / Prefix Tree
Trie Operations
Design Patterns
Strings
Intermediate

555

13