Algorithms, explained simply
30 classic algorithms - each with a step-by-step visualization, JavaScript code, and a comparison with its closest relatives.
30 of 30 published - more added regularly.
Sorting
Put things in order - the classic starting point.Bubble Sort
Swap neighbours until the biggest value floats to the end.
Selection Sort
Find the smallest, put it in front, repeat.
Insertion Sort
Build a sorted run one card at a time, like a poker hand.
Merge Sort
Split in half, sort each half, merge the two back together.
Quick Sort
Pick a pivot, split around it, recurse on both sides.
Heap Sort
Turn the array into a heap, then pop the max n times.
Counting Sort
Count how many of each value, then rewrite the array. No comparisons.
Radix Sort
Sort by last digit, then next digit, until you run out of digits.
Searching
Find a value, or a window, inside a collection.Linear Search
Check every item until you find it. Simple and always works.
Binary Search
Halve a sorted range each step - 1M items in 20 checks.
Two Pointers
Walk two cursors toward each other instead of nesting loops.
Sliding Window
Slide a range across the array, adding one end and dropping the other.
Graphs
Nodes and edges: traversal, shortest paths, connectivity.Breadth-First Search
Explore ring by ring with a queue. Finds the fewest-hops path.
Depth-First Search
Go as deep as possible, then back up and try the next branch.
Dijkstra's Algorithm
Cheapest path first, using a priority queue. No negative weights.
Bellman–Ford
Relax every edge V−1 times. Slower than Dijkstra, but handles negatives.
Topological Sort
Order tasks so every dependency comes before what needs it.
Union–Find (DSU)
Track which items are connected, in near-constant time.
Kruskal's MST
Sort the edges, add the cheap ones that don't make a cycle.
Trees
Hierarchical data - traversal, search trees, prefix trees.Tree Traversals
Pre-order, in-order, post-order - same walk, three moments to visit.
Level-Order Traversal
Read a tree row by row, top to bottom, with a queue.
Binary Search Tree
Smaller left, bigger right - insert, find and delete in O(log n).
Trie (Prefix Tree)
One node per character - the data structure behind autocomplete.
Dynamic Programming
Solve once, remember, reuse.Fibonacci: Memo vs Tabulation
The clearest example of turning O(2ⁿ) into O(n) by remembering.
Kadane's Algorithm
Largest sum of any run of numbers, in a single pass.
0/1 Knapsack
Fit the most value into a fixed bag - take an item or leave it.
Longest Common Subsequence
The grid behind every diff tool you've ever used.
Coin Change
Fewest coins for an amount - where greedy quietly fails.