Logn - Algorithm Complexity Visualization Logo

Visual intuition for algorithm complexity

Contribute on GitHub

Big-O Cheat Sheet

Click on any algorithm card below to view detailed information, complexity analysis, and use cases

Search Algorithms

Linear Search

Time: O(n)

Space: O(1)

Check each element sequentially until found.

Binary Search

Time: O(log n)

Space: O(1)

Divide search space in half at each step.

Jump Search

Time: O(√n)

Space: O(1)

Jump ahead by fixed steps, then linear search.

Interpolation Search

Time: O(log log n) avg, O(n) worst

Space: O(1)

Estimate position using value distribution.

Sorting Algorithms

Bubble Sort

Time: O(n²)

Space: O(1)

Compare adjacent elements and swap if needed.

Merge Sort

Time: O(n log n)

Space: O(n)

Divide array, sort recursively, then merge.

Quick Sort

Time: O(n log n) avg, O(n²) worst

Space: O(log n)

Partition around pivot, sort recursively.

Insertion Sort

Time: O(n) best, O(n²) worst

Space: O(1)

Build sorted array one element at a time.

Selection Sort

Time: O(n²)

Space: O(1)

Find minimum and swap with current position.

Heap Sort

Time: O(n log n)

Space: O(1)

Build heap, extract max repeatedly.

Radix Sort

Time: O(nk)

Space: O(n+k)

Sort by individual digits, k = number of digits.

Counting Sort

Time: O(n+k)

Space: O(k)

Count occurrences, k = range of values.

Shell Sort

Time: O(n log² n)

Space: O(1)

Generalization of insertion sort with gaps.

Bucket Sort

Time: O(n+k) avg, O(n²) worst

Space: O(n+k)

Distribute elements into buckets, then sort each.

Graph Algorithms

Depth-First Search

Time: O(V+E)

Space: O(V)

Explore as far as possible before backtracking.

Breadth-First Search

Time: O(V+E)

Space: O(V)

Explore level by level using a queue.

Dijkstra's Algorithm

Time: O((V+E) log V)

Space: O(V)

Find shortest path using priority queue.

Topological Sort

Time: O(V+E)

Space: O(V)

Linear ordering of vertices in directed acyclic graph.

Bellman-Ford

Time: O(VE)

Space: O(V)

Shortest path with negative weights, detects cycles.

Floyd-Warshall

Time: O(V³)

Space: O(V²)

All-pairs shortest paths using dynamic programming.

Kruskal's Algorithm

Time: O(E log E)

Space: O(V)

Minimum spanning tree using union-find.

Prim's Algorithm

Time: O(E log V)

Space: O(V)

Minimum spanning tree using priority queue.

Tree Algorithms

BST Operations

Time: O(log n) avg, O(n) worst

Space: O(log n) avg, O(n) worst

Search, insert, delete in binary search tree.

Tree Traversal

Time: O(n)

Space: O(h)

Inorder, preorder, postorder traversal. h = height.

Trie Operations

Time: O(m)

Space: O(ALPHABET_SIZE × m × N)

Search, insert, delete. m = key length, N = keys.

Data Structures

Hash Table Lookup

Time: O(1) avg, O(n) worst

Space: O(n)

Direct access via hash function mapping.

Binary Heap Insert/Remove

Time: O(log n)

Space: O(1)

Maintain heap property by bubbling up/down.

Binary Heap Build

Time: O(n)

Space: O(1)

Build heap from unsorted array efficiently.

String Algorithms

KMP Algorithm

Time: O(n+m)

Space: O(m)

Pattern matching using failure function.

Rabin-Karp

Time: O(n+m) avg, O(nm) worst

Space: O(1)

Pattern matching using rolling hash.

Dynamic Programming

Longest Common Subsequence

Time: O(nm)

Space: O(nm)

Find longest subsequence common to two strings.

Edit Distance

Time: O(nm)

Space: O(min(n,m))

Levenshtein distance: min edits to transform string.

Interactive Complexity Visualizer

Understanding the Complexities