Algorithm Visualizations
Interactive visualizations of common algorithms used in LeetCode problems. Each one runs step by step and prints the trace underneath.
Nothing matches that.
Sorting
Bubble Sort
Repeatedly swap adjacent out-of-order elements.
O(n²)StableInsertion Sort
Insert each element into its correct position. Fast for nearly sorted.
O(n²)StableSelection Sort
Find minimum, swap to front each pass.
O(n²)Merge Sort
Divide-and-conquer: split, sort, merge.
O(n log n)StableQuick Sort
Partition around pivot, recurse on halves.
O(n log n) avgIn-placeHeap Sort
Build max-heap, extract max repeatedly. LC 215, 347.
O(n log n)In-placeBucket Sort
Distribute into buckets, sort each, concatenate. LC 347, 451.
O(n+k) avgSearching
Linear Search
Scan every element one by one.
O(n)Binary Search
Halve the search space each step on sorted data. LC 704, 33, 153.
O(log n)Graph
BFS
Level-by-level exploration using a queue. LC 102, 200, 994.
O(V+E)Shortest PathDFS
Explore as deep as possible, then backtrack. LC 200, 695, 79.
O(V+E)StackBidirectional BFS
Expand from S and E simultaneously; meet in the middle. LC 127, 433, 752.
O(b^(d/2))FasterMulti-Source BFS
Enqueue all sources at t=0; spread like ripples. LC 994, 542, 1162.
O(V+E)Multi-startGraph + Backtracking
DFS all paths SāE; undo visited on backtrack. LC 79, 980, 1219.
O(4^V)All pathsDijkstra
Shortest paths in weighted graphs (non-negative). LC 743, 1631.
O((V+E) log V)Min-HeapBellman-Ford
Shortest paths with negative weights. Detects negative cycles. LC 787.
O(V·E)Floyd-Warshall
All-pairs shortest paths via intermediate vertices. LC 2642.
O(V³)Topological Sort
Find ordering in a DAG (Kahn's BFS). LC 207, 210, 269.
O(V+E)Union-Find
Track connected components with path compression. LC 200, 547, 684.
O(α(n))Array Techniques
Two Pointers
Converge left & right on sorted array to find target sum. LC 167, 15, 11.
O(n)SortedSliding Window
Fixed-size window slides to find max sum subarray. LC 643, 209, 3, 76.
O(n)Prefix Sum
O(1) range-sum queries after O(n) build. LC 303, 304, 560, 523.
O(1) queryKadane's Algorithm
Maximum subarray sum in one pass. LC 53, 152, 918.
O(n)Difference Array
O(1) range updates, prefix-sum to build result. LC 370, 1109.
O(n)String Matching
KMP Algorithm
Knuth-Morris-Pratt: failure function skips redundant comparisons. LC 28, 214, 1392.
O(n+m)Failure fnRolling Hash
Rabin-Karp: slide a window, update hash in O(1). Detect substring matches by hash. LC 28, 187, 1044.
O(n+m) avgRabin-KarpDynamic Programming
1D DP
Build dp[i] from dp[i-1], dp[i-2]. Climbing Stairs, House Robber, Fibonacci. LC 70, 198, 509.
O(n)Tabulation0/1 Knapsack
Take or skip each item. Fill 2D table row-by-row from prior row. LC 416, 494, 1049.
O(n·W)Take/Skip2D DP
Fill a grid cell-by-cell. Unique Paths, Min Path Sum, LCS. LC 62, 64, 1143.
O(m·n)GridString DP
Edit Distance (insert/delete/replace) & Longest Palindromic Subsequence. LC 72, 5, 516.
O(m·n)Edit / LPSTree DP
Post-order DFS; each node carries a dp tuple (rob/skip, gain, depth). LC 337, 124, 543.
O(n)Post-orderStack
Tree
Binary Tree Traversal
Inorder / Preorder / Postorder / Level-order with visit numbering. LC 94, 144, 145, 102.
O(n)DFS / BFSLowest Common Ancestor
Post-order DFS: bubble p/q up; first node holding both is LCA. LC 236, 235, 1123.
O(n)Post-order