Algorithm Complexity Cheatsheet: The Ultimate Comparison

A comprehensive reference table for time and space complexities of sorting, graph algorithms, and common DSA patterns.

Memorizing complexities is one thing, but having a clear, comparative view of how different algorithms perform across best, average, and worst-case scenarios is essential for effective problem-solving and system design.

Sorting Algorithms

AlgorithmBest CaseAverage CaseWorst CaseSpace Complexity
QuicksortO(N log N)O(N log N)O(N^2)O(log N)
MergesortO(N log N)O(N log N)O(N log N)O(N)
HeapsortO(N log N)O(N log N)O(N log N)O(1)
Bubble SortO(N)O(N^2)O(N^2)O(1)
Insertion SortO(N)O(N^2)O(N^2)O(1)
Selection SortO(N^2)O(N^2)O(N^2)O(1)

Graph Algorithms

AlgorithmTime ComplexitySpace Complexity
DFS / BFSO(V + E)O(V)
Dijkstra (with Binary Heap)O((V + E) log V)O(V)
Bellman-FordO(VE)O(V)
Floyd-WarshallO(V^3)O(V^2)
Prim (with Binary Heap)O((V + E) log V)O(V)
KruskalO(E log E)O(V)

Data Structure Operations

StructureAccess / SearchInsertion / Deletion
Hash TableAvg O(1), Worst O(N)Avg O(1), Worst O(N)
Balanced BST (AVL, R-B)O(log N)O(log N)
Stack / QueueO(N) (top is O(1))O(1)
Linked ListO(N)O(1)

Want to see this in action?

Jump directly into the time complexity calculator to see how code translates to Big O growth.

Open Time Complexity Calculator

Related Articles