Coding patternsTrees, graphs and heaps
Coding patterns for trees, graphs and heaps
Depth-first and breadth-first traversal, topological sort, the heap and the trie: how to walk a structure, find shortest paths, order dependencies, keep the best k items and look up prefixes.
4 topics.
- 01FoundationReadTree traversalMost tree problems are one recursive question: what does each subtree hand back?
- 02Mid-levelReadGraph searchBFS for shortest paths, DFS for reachability, and topological sort for dependencies.
- 03Mid-levelReadHeaps and top-kKeep the k best items with a heap of size k, and merge sorted streams lazily.
- 04Mid-levelReadTriesA tree of prefixes: look up a word or prefix in O(length), however many words are stored.
More in Coding patterns
The designbeyondcode digest, every Saturday
New deep dives, interview tips and site news in one short email. Free. Leave with one click.
We never sell or share your email. We only use it to send this newsletter.