Complexity & Big-O Quick Reference
Compact reference tables for time and space complexities of all major data structures and algorithms.
In production systems and competitive programming, hardware limits enforce a strict runtime constraint: modern CPUs execute approximately basic operations per second. Knowing the asymptotic bounds of standard data structures and algorithms allows engineers to immediately evaluate whether an approach is physically viable before writing a single line of code.
Learning Objectives
#By the end of this chapter, you will be able to:
- Correlate input sizes () with asymptotic bounds to identify viable algorithmic complexities under a 1-second CPU budget.
- Compare the access, search, insertion, and deletion bounds of all major linear and hierarchical data structures.
- Select sorting algorithms based on time/space trade-offs, in-place constraints, and stability requirements.
- Identify graph algorithm runtimes, auxiliary space bounds, and precondition requirements (e.g., non-negative edge weights or acyclic constraints).
1. Asymptotic Growth Rates & 1-Second CPU Budgets
#The following table benchmarks operational counts as scales, assuming a standard budget of operations per second:
| Complexity | Name | Viable Input Size for 1 sec ( ops) | ||||
|---|---|---|---|---|---|---|
| Constant | Any input size () | |||||
| Logarithmic | Huge () | |||||
| c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 | ||||||
| c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 | ||||||
| c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 | ||||||
| s173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429 | ||||||
| c69,-144,104.5,-217.7,106.5,-221 | ||||||
| l0 -0 | ||||||
| c5.3,-9.3,12,-14,20,-14 | ||||||
| H400000v40H845.2724 | ||||||
| s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 | ||||||
| c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z | ||||||
| M834 80h400000v40h-400000z"/>) | Sublinear | Very Large () | ||||
| Linear | Large () | |||||
| Linearithmic | Medium-Large () | |||||
| Quadratic | (TLE) | Moderate () | ||||
| Cubic | (TLE) | (TLE) | Small () | |||
| Exponential | Intractable | Intractable | Tiny () | |||
| Factorial | Intractable | Intractable | Intractable | Micro () |
2. Master Data Structure Operations Table
#Values denote Worst-Case performance unless explicitly annotated as Amortized or Average.
| Data Structure | Access by Index | Search by Value | Insert at Head | Insert at Tail | Insert Arbitrary | Delete at Head | Delete at Tail | Delete Arbitrary | Space Complexity |
|---|---|---|---|---|---|---|---|---|---|
| Static Array | — | — | — | — | — | — | |||
| Dynamic Array | |||||||||
| Singly Linked List | |||||||||
| Doubly Linked List | |||||||||
| Stack | — | [Push] | — | — | [Pop] | — | — | ||
| Queue | — | — | [Enqueue] | — | [Dequeue] | — | — | ||
| Deque | |||||||||
| Hash Table | — | ||||||||
| Binary Search Tree | — | — | — | — | — | ||||
| AVL Tree (Balanced) | — | — | — | — | — | ||||
| Binary Heap | [Peek] | — | — | [Push] | [Extract] | — |
Amortized time for push-back; resizing takes worst-case.
Assuming a maintained tail pointer.
Given direct pointer reference to the target node.
3. Master Sorting Algorithms Table
#| Algorithm | Best Time | Average Time | Worst Time | Auxiliary Space | In-Place? | Stable? | Paradigm |
|---|---|---|---|---|---|---|---|
| Bubble Sort | Yes | Yes | Comparison / Exchange | ||||
| Selection Sort | Yes | No | Comparison / Selection | ||||
| Insertion Sort | Yes | Yes | Comparison / Insertion | ||||
| Merge Sort | No | Yes | Divide & Conquer | ||||
| Quick Sort | Yes | No | Divide & Conquer / Partition | ||||
| Heap Sort | Yes | No | Selection / Heap Structure | ||||
| Counting Sort | No | Yes | Non-Comparison / Distribution | ||||
| Radix Sort | No | Yes | Non-Comparison / Positional | ||||
| Bucket Sort | No | Yes | Non-Comparison / Bucketing |
4. Master Graph Algorithms Table
#| Algorithm | Problem Solved | Time Complexity | Space Complexity | Graph Preconditions |
|---|---|---|---|---|
| BFS | Shortest path in unweighted graph | Any graph | ||
| DFS | Connectivity, cycles, flood-fill | Any graph | ||
| Kahn's (BFS) | Topological ordering | Directed Acyclic Graph (DAG) | ||
| Dijkstra | Single-Source Shortest Path (SSSP) | Non-negative edge weights () | ||
| Bellman-Ford | SSSP & Negative Cycle Detection | No negative cycles reachable from source | ||
| Floyd-Warshall | All-Pairs Shortest Path (APSP) | No negative cycles | ||
| Prim's | Minimum Spanning Tree (MST) | Connected, undirected graph | ||
| Kruskal's | Minimum Spanning Tree (MST) | Connected, undirected graph | ||
| Tarjan's | Strongly Connected Components | Directed graph |
5. Key Takeaways
#- Input Bound Rule of Thumb: For , algorithms pass comfortably; for , is required; for , only strictly or approaches complete within 1 second.
- Cache Locality Trade-Off: While linked lists guarantee head insertion, arrays frequently outperform them in wall-clock benchmarks due to cache lines and contiguous memory fetches.
- Precondition Awareness: Always check edge-weight constraints before choosing between Dijkstra, Bellman-Ford, and Floyd-Warshall.
References & Academic Attribution
#- Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2022). Introduction to Algorithms (4th ed.), Chapters 1–3, 6–9, 22–24. MIT Press.
- Sedgewick, R., & Wayne, K. (2011). Algorithms (4th ed.). Addison-Wesley.
- Knuth, D. E. (1998). The Art of Computer Programming, Volume 3: Sorting and Searching (2nd ed.). Addison-Wesley.