Click on any algorithm card below to view detailed information, complexity analysis, and use cases
Time: O(n)
Space: O(1)
Check each element sequentially until found.
Time: O(log n)
Space: O(1)
Divide search space in half at each step.
Time: O(√n)
Space: O(1)
Jump ahead by fixed steps, then linear search.
Time: O(log log n) avg, O(n) worst
Space: O(1)
Estimate position using value distribution.
Time: O(n²)
Space: O(1)
Compare adjacent elements and swap if needed.
Time: O(n log n)
Space: O(n)
Divide array, sort recursively, then merge.
Time: O(n log n) avg, O(n²) worst
Space: O(log n)
Partition around pivot, sort recursively.
Time: O(n) best, O(n²) worst
Space: O(1)
Build sorted array one element at a time.
Time: O(n²)
Space: O(1)
Find minimum and swap with current position.
Time: O(n log n)
Space: O(1)
Build heap, extract max repeatedly.
Time: O(nk)
Space: O(n+k)
Sort by individual digits, k = number of digits.
Time: O(n+k)
Space: O(k)
Count occurrences, k = range of values.
Time: O(n log² n)
Space: O(1)
Generalization of insertion sort with gaps.
Time: O(n+k) avg, O(n²) worst
Space: O(n+k)
Distribute elements into buckets, then sort each.
Time: O(V+E)
Space: O(V)
Explore as far as possible before backtracking.
Time: O(V+E)
Space: O(V)
Explore level by level using a queue.
Time: O((V+E) log V)
Space: O(V)
Find shortest path using priority queue.
Time: O(V+E)
Space: O(V)
Linear ordering of vertices in directed acyclic graph.
Time: O(VE)
Space: O(V)
Shortest path with negative weights, detects cycles.
Time: O(V³)
Space: O(V²)
All-pairs shortest paths using dynamic programming.
Time: O(E log E)
Space: O(V)
Minimum spanning tree using union-find.
Time: O(E log V)
Space: O(V)
Minimum spanning tree using priority queue.
Time: O(log n) avg, O(n) worst
Space: O(log n) avg, O(n) worst
Search, insert, delete in binary search tree.
Time: O(n)
Space: O(h)
Inorder, preorder, postorder traversal. h = height.
Time: O(m)
Space: O(ALPHABET_SIZE × m × N)
Search, insert, delete. m = key length, N = keys.
Time: O(1) avg, O(n) worst
Space: O(n)
Direct access via hash function mapping.
Time: O(log n)
Space: O(1)
Maintain heap property by bubbling up/down.
Time: O(n)
Space: O(1)
Build heap from unsorted array efficiently.
Time: O(n+m)
Space: O(m)
Pattern matching using failure function.
Time: O(n+m) avg, O(nm) worst
Space: O(1)
Pattern matching using rolling hash.
Time: O(nm)
Space: O(nm)
Find longest subsequence common to two strings.
Time: O(nm)
Space: O(min(n,m))
Levenshtein distance: min edits to transform string.