AlgoTrace — algorithms, step by step
Interactive algorithm visualizer with highlighted pseudocode, play/pause/scrub controls and edge-case presets, plus a code tracer for your own Python, JavaScript, C++ or Java.
Sorting algorithms
Put things in order — comparisons, swaps, and the tricks that avoid them.
- Bubble Sort — Repeatedly swap adjacent out-of-order pairs; the largest value bubbles to the end each pass.
- Selection Sort — Find the minimum of the unsorted part and swap it to the front.
- Insertion Sort — Grow a sorted prefix by inserting each new value into its correct slot.
- Cocktail Shaker Sort — Bubble sort that alternates direction, moving large values right and small values left.
- Shell Sort — Insertion sort over shrinking gaps, so values travel long distances early.
- Merge Sort — Divide in half, sort each half recursively, then merge the two sorted halves.
- Quick Sort — Partition around a pivot so smaller values go left and larger go right, then recurse.
- Heap Sort — Build a max-heap, then repeatedly move the root (maximum) to the end and re-heapify.
- Counting Sort — Count occurrences of each value, then rebuild the array from the counts.
- Radix Sort (LSD) — Sort by the ones digit, then tens, then hundreds — each pass is a stable bucket sort.
Searching algorithms
Find a needle fast by exploiting order.
- Linear Search — Check every element from left to right until the target appears.
- Binary Search — Halve a sorted search range each step by comparing against the middle.
- Jump Search — Jump ahead √n at a time to find the right block, then scan it linearly.
- Interpolation Search — Guess where the target should be from its value, like looking up a name in a phone book.
- Exponential Search — Double a bound until it passes the target, then binary search inside that range.
- Ternary Search — Split a sorted range into thirds with two probes and keep the third that can hold the target.
Graphs algorithms
Traversal, shortest paths, spanning trees and ordering.
- Breadth-First Search — Explore level by level with a queue — gives shortest paths in unweighted graphs.
- Depth-First Search — Go as deep as possible along each branch before backtracking.
- Dijkstra's Shortest Path — Greedily settle the closest unsettled vertex using a priority queue.
- Bellman–Ford — Relax every edge V−1 times; handles negative weights and detects negative cycles.
- Prim's MST — Grow one tree by always adding the cheapest edge leaving it.
- Kruskal's MST — Sort edges by weight and add each one unless it would create a cycle (union–find).
- Topological Sort (Kahn) — Order a DAG so every edge points forward, by repeatedly removing zero in-degree vertices.
- Floyd–Warshall — All-pairs shortest paths by allowing one more intermediate vertex k at a time.
- A* Pathfinding — Best-first search on a grid using cost-so-far g plus a heuristic h towards the goal.
Dynamic Programming algorithms
Solve each subproblem once and reuse the answer.
Greedy algorithms
Take the locally best choice — and learn when that fails.
- Activity Selection — Pick the most non-overlapping intervals by always taking the one that ends first.
- Fractional Knapsack — Take items by best value per weight; split the last one if it does not fully fit.
- Greedy Coin Change — Repeatedly take the largest coin that still fits — optimal only for some coin systems.
- Jump Game — Can you reach the last index if A[i] is the max jump length from i? Track the farthest reach.
- Huffman Coding — Build an optimal prefix code by repeatedly merging the two least frequent symbols.
Backtracking algorithms
Try, recurse, undo.
- N-Queens — Place N queens so none attack each other; undo a placement when it leads to a dead end.
- Subset Sum — Find a subset adding up to a target by deciding include/exclude for each item.
- Permutations — Generate every ordering by choosing an unused element for each position, then undoing.
Trees algorithms
Hierarchies and binary search trees.
- BST Insert & Search — Insert values into a binary search tree, then search for a key by walking left or right.
- Tree Traversals — Visit every node in-order, pre-order, post-order or level-order.
Techniques algorithms
Two pointers, sliding windows and other patterns.
Time and space complexity cheatsheet