Algorithm Visualizations

Interactive visualizations of common algorithms used in LeetCode problems.

Sorting

Bubble Sort

Repeatedly swap adjacent out-of-order elements.

O(n²)Stable

Insertion Sort

Insert each element into its correct position. Fast for nearly sorted.

O(n²)Stable

Selection Sort

Find minimum, swap to front each pass.

O(n²)

Merge Sort

Divide-and-conquer: split, sort, merge.

O(n log n)Stable

Quick Sort

Partition around pivot, recurse on halves.

O(n log n) avgIn-place

Heap Sort

Build max-heap, extract max repeatedly. LC 215, 347.

O(n log n)In-place

Bucket Sort

Distribute into buckets, sort each, concatenate. LC 347, 451.

O(n+k) avg

Searching

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 Path

DFS

Explore as deep as possible, then backtrack. LC 200, 695, 79.

O(V+E)Stack

Bidirectional BFS

Expand from S and E simultaneously; meet in the middle. LC 127, 433, 752.

O(b^(d/2))Faster

Multi-Source BFS

Enqueue all sources at t=0; spread like ripples. LC 994, 542, 1162.

O(V+E)Multi-start

Graph + Backtracking

DFS all paths S→E; undo visited on backtrack. LC 79, 980, 1219.

O(4^V)All paths

Dijkstra

Shortest paths in weighted graphs (non-negative). LC 743, 1631.

O((V+E) log V)Min-Heap

Bellman-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)Sorted

Sliding 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) query

Kadane'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)

Stack

Monotonic Stack

Next Greater Element: decreasing stack, pop when larger found. LC 496, 739, 84.

O(n)Stack

Tree

Binary Tree Traversal

Inorder / Preorder / Postorder / Level-order with visit numbering. LC 94, 144, 145, 102.

O(n)DFS / BFS

Lowest Common Ancestor

Post-order DFS: bubble p/q up; first node holding both is LCA. LC 236, 235, 1123.

O(n)Post-order

Data Structures

LRU Cache

Least Recently Used cache with O(1) get/put. LC 146.

O(1)HashMap + DLL

LFU Cache

Least Frequently Used: evict min-freq key (LRU tiebreak). LC 460.

O(1)Freq buckets