Big O reference for coding interviews

Time and space complexity, with the fine print.

34 data structures, algorithms, and patterns. Every bound says whether it is average, amortized, or worst case, and what it assumes.

What's here

Reference

  1. Topics

    All 34 topics with search and filters. Each has its own page with code and pitfalls.

  2. Big O basics

    What the notation means, a growth playground, and how to read the tables.

  3. Data structures

    Arrays, hash tables, trees, heaps, tries, Union-Find, and graph representations.

  4. Sorting

    Best, average, and worst case for 13 sorts, with the footnotes that matter.

  5. Search and graphs

    Binary search, BFS, DFS, heaps, shortest paths, and spanning trees.

  6. Coding patterns

    Typical costs of two pointers, sliding window, backtracking, and DP.

Tools

  1. Complexity lookup

    Best, average, and worst case for one operation, with its caveat.

  2. Compare two algorithms

    Time, space, stability, and trade-offs side by side.

  3. Visualizer

    Step through searches, four sorts, BFS, and DFS one move at a time.

  4. Export and share

    Markdown, CSV, printable cards, and PDFs.

Practice

  1. Roadmap

    A suggested order for the topics, with prerequisites and progress.

  2. Quiz

    Ten random questions with an explanation after each answer.

  3. Code challenges

    Predict the time and space of short snippets in three languages.

  4. Revision sheet

    The high-relevance topics on one printable page.

The ones you will be asked about

If you only memorize eight lines, make it these. Each links to the full explanation, and the lookup has the assumptions.

OperationAverageWorst
Hash table lookup, insert, deleteO(1) expectedO(n)
Binary searchO(log n)O(log n)
Binary heap popO(log n)O(log n)
Merge sortO(n log n)O(n log n)
QuicksortO(n log n)O(n²)
Breadth-first searchO(V + E)O(V + E)
Dijkstra shortest pathO((V + E) log V)O((V + E) log V)
Union-Find find and unionO(α(n)) amortizedO(α(n)) amortized

The hash table worst case assumes many keys collide. Quicksort hits O(n²) when the pivot keeps splitting badly, such as a first-element pivot on sorted input. The colors match the strip at the top of every page: green is cheapest, dark red is exponential.

Found a bound that looks wrong? Open an issue with a source, and it gets fixed.

Keyboard shortcuts

/
Search topics
?
Show this list of shortcuts
r
Open the revision sheet
b
Save or unsave the focused card, or the topic you are reading
l
Mark the focused card, or the topic you are reading, as learned
Space Left arrow Right arrow
In the visualizer: play or pause, step back, step forward
1 to 4 Enter
In the quiz: pick an answer, then go to the next question
Escape
Close this list