Everything in CodeViz
Two collections, both free and both interactive: 48 algorithm pages covering Princeton's Algorithms Part I and II, and 55 built-in problems with a full statement, a worked solution and test cases. Everything opens in the visualizer and runs on input you choose.
Pages
- Home — the visualizer/Write or paste Python and step through it: variables, arrays, recursion trees, call stacks
- Algorithms/algs/index.htmlEvery core algorithm from Princeton's Algorithms Part I & II, in Python, animated
- All problems/sitemap.htmlThis index: every algorithm page and every built-in problem
Algorithms, visualized · 48 pages
Every core algorithm from Princeton's Algorithms Part I and Part II, in lecture order. Each page has the Python, its cost, the invariant that makes it correct, and a step-by-step animation you drive yourself. Start at the index, or open any algorithm below.
Part I — data types, sorting, searching
Union–Find
- Quick-findKeep a component identifier for every site.
- Quick-unionReinterpret the same array as parent pointers.
- Weighted quick-unionOne comparison added to union guarantees no tree is ever deeper than lg n.
- Path compressionEvery find already walks to the root, so pay one more pass and point the whole path at it.
Analysis of algorithms
- Binary searchHalve the interval that could still contain the key.
- 3-sum (brute force)Count triples summing to zero by trying all of them.
Stacks and queues
- Stack (linked list)Push and pop at the front of a singly linked list.
- Stack (resizing array)Keep items in an array and double it when it fills.
- Queue (linked list)Enqueue at the back, dequeue from the front.
Elementary sorts
- Selection sortFind the smallest remaining key and swap it into place.
- Insertion sortSlide each key left until it lands.
- ShellsortInsertion sort, but comparing keys h apart.
- Knuth shuffleSwap each item with a random earlier one.
Sorting applications
Mergesort
- Mergesort (top-down)Sort each half, then merge.
- Bottom-up mergesortMerge every adjacent pair, then every pair of pairs, doubling the width each pass.
Quicksort
- QuicksortPut one key where it belongs and everything smaller to its left.
- QuickselectPartition, then recur on the one side that can contain the answer.
- 3-way quicksortPartition into less-than, equal-to and greater-than.
Priority queues
- Binary heap (MaxPQ)A complete binary tree stored in an array, where no key exceeds its parent.
- HeapsortHeapify the array bottom-up, then repeatedly swap the root to the end.
Binary search trees
Balanced search trees
Hash tables
- Separate chainingHash each key to one of m lists and search that list.
- Linear probingOne key per slot: on a collision, step right until you find an empty one.
- Depth-first searchMark a vertex, then recur into any unmarked neighbour.
- Breadth-first searchSwap the recursion for a queue and vertices come off in order of distance.
- Connected componentsRun DFS from each vertex no earlier search reached.
- Directed cycle detectionAn edge to a vertex still on the recursion stack closes a cycle.
- Topological sortAdd each vertex to a list only after everything it points to is finished, then reverse the list.
- Strong components (Kosaraju–Sharir)Reverse the digraph, take its reverse postorder, then DFS the original in that order.
- Kruskal's MSTSort the edges and take them in order, skipping any that would create a cycle.
- Prim's MST (lazy)Keep one growing tree and always add the cheapest edge leaving it.
- Dijkstra's algorithmRepeatedly settle the unsettled vertex closest to the source and relax its edges.
- Shortest paths in a DAGIn an acyclic digraph, relax vertices in topological order and one pass is enough.
- Bellman–FordRelax every edge, V−1 times.
- Key-indexed countingCount how many keys have each value, turn the counts into starting positions, then place every key directly where it belongs.
- LSD radix sortSort by the last character, then the one before it, and so on.
- MSD radix sortSort on the first character, then recur inside each group.
- Brute-force substring searchTry every alignment, comparing left to right.
- Knuth–Morris–PrattPrecompute, for every state and character, where a mismatch leaves you.
- Boyer–MooreCompare the pattern right to left.
- Rabin–KarpHash the pattern once, then hash every window of the text — each in constant time from the previous one.
- Run-length encodingReplace each run of identical symbols by the symbol and its length.
- Huffman compressionMerge the two least frequent symbols, repeatedly.
- LZW compressionEmit the code for the longest known phrase, then learn that phrase plus one more character.
- Two SumHash Map
- Subarray Sum Equals KPrefix sum + hash map
- First Unique CharacterHash-table buckets view
- Sliding Window Maximum SumFixed-size window
- Longest Substring Without RepeatSliding window (string band)
- Daily TemperaturesMonotonic stack (next greater)
- Valid ParenthesesStack view
- Min StackDesign - a second stack of minimums
- Binary Tree Inorder TraversalTree Recursion
- Binary Tree Level OrderTree BFS (queue)
- Search in a BSTBinary Search Tree
- Morris Inorder TraversalThreaded Tree · O(1) Space
- Breadth-First SearchGraph + Queue
- Depth-First SearchGraph + Recursion
- Dijkstra's Shortest PathWeighted Graph + Heap
- Topological SortDirected Graph (Kahn)
- Number of IslandsGrid DFS + flood fill
- Number of Connected ComponentsUnion-Find / DSU forest
- Bellman-Ford Shortest PathEdge relaxation (handles negatives)
- Kruskal's Minimum Spanning TreeSorted edges + Union-Find
- Floyd-Warshall (All-Pairs)DP over intermediate nodes
- Maximum Subarray (Kadane's)Running-max 1D DP
- Climbing StairsRecursion + Memoization
- Coin Change1D Dynamic Programming
- Longest Common Subsequence2D Dynamic Programming
- 0/1 Knapsack2D Dynamic Programming
- KMP String SearchPattern Matching
- Rabin-Karp Substring SearchRolling hash
- Z-AlgorithmPrefix-match array
- Manacher's Longest PalindromeLinear-time palindromes
- Sieve of EratosthenesPrime sieve (boolean array)
- Euclidean GCDRecursion Tree
- Fast Modular ExponentiationBinary exponentiation
- Fibonacci by Matrix PowerMatrix exponentiation - O(log n)
Part II — graphs, strings, compression
Undirected graphs
Directed graphs
Minimum spanning trees
Shortest paths
Maximum flow
Radix sorts
Tries
Substring search
Data compression
Examples · 55 problems
Built-in problems that load straight into the visualizer, grouped by the pattern each one teaches and then by algorithm family. Every one carries a full statement, a worked solution and test cases: watch it run on your own input, then read why it is built that way.