The Big-O cheat sheet
Time and space complexity for every structure and sort you'll meet in an interview — colour-coded so the expensive ones jump out. Scrub the chart to feel how each class explodes as n grows.
The complexity classes, fastest to slowest
Data structure operations
average-case unless noted · *heap access = peek min/max
Sorting algorithms
Frequently asked
What is the time complexity of common data structures?+
Arrays give O(1) access but O(n) search and insertion in the middle. Hash tables give O(1) average insert, search, and delete. Balanced binary search trees give O(log n) for search, insert, and delete while keeping elements ordered. Heaps give O(1) access to the min or max and O(log n) insert and extract.
Which sorting algorithm is the fastest?+
For general data, the O(n log n) comparison sorts — merge sort, quicksort, and heapsort — are the fastest you can do with comparisons. Quicksort is usually fastest in practice due to cache behaviour, but its worst case is O(n²); merge sort guarantees O(n log n) and is stable; heapsort guarantees O(n log n) in O(1) extra space.
Why do we drop constants and lower-order terms in Big-O?+
Big-O describes how an algorithm scales as the input grows toward infinity, not its exact running time. As n grows, the highest-order term dominates and constants become irrelevant — O(2n + 100) and O(n) describe the same linear growth, so both are written O(n).