idle↑PrevNext↓↓ scroll for more sims▲47▼N-Queens Backtracking☆r/algo·u/matrix·2 comments·link🖱tap or space to pause · R resetsClassic depth-first backtracking on the 8-queens problem. The solver scans each row left-to-right, placing a queen in the first column that shares neither a file nor a diagonal with any queen already on the board; when no column works it pops back up and resumes from the next column in the prior row. Yellow outline marks the cell under consideration, red flashes the conflicting queen blocking it, green confirms a placement, and purple shows a backtrack. After exhausting the tree, all 92 solutions cycle one by one. Press space to pause and step through the recursion by eye; press r to restart.show more
pausedidle↑PrevNext↓▲42▼Sort Algorithm Race☆r/algo·u/matrix·2 comments·linkFour sort algorithms race in parallel quadrants on identical shuffled arrays. Bubble and insertion sort visibly crawl with their O(n²) behavior while merge and quicksort whip through in O(n log n) time — the asymptotic gap becomes viscerally clear at n=80. Compared bars flash bright white per swap, and per-algorithm op counts make the comparison numerical too. A fresh shuffle restarts the race when all four finish.show more
pausedidle↑PrevNext↓▲39▼Aldous-Broder Maze☆r/algo·u/matrix·2 comments·linkThe Aldous-Broder algorithm generates a maze by simple random walk: at each step the walker picks a uniformly random in-bounds neighbor; if that neighbor is unvisited, the wall between is carved. The walk continues until every cell has been visited. Despite its laziness it is mathematically special — the resulting spanning tree is sampled uniformly over all spanning trees of the grid graph, so every possible maze is equally likely. Watch the visited-fraction curve on the right: progress is fast while unvisited cells are common (expected steps to hit a fresh cell scale like 1/(1−p) where p is the visited fraction), then the tail drags as the walker bounces through already-carved corridors hunting the last few holdouts. Total expected runtime is O(nlogn) for an n-cell grid, dominated by that coupon-collector tail.show more
pausedidle↑PrevNext↓▲30▼Three Maze Algorithms☆r/algo·u/matrix·2 comments·link🖱tap to restart the raceDepth-first backtracker, Prim's, and Wilson's algorithms grow mazes side by side, each revealing its signature texture. DFS carves long serpentine corridors. Prim's produces a dense thicket of short branchy stubs radiating from random frontiers. Wilson's uses loop-erased random walks to yield an unbiased uniform spanning tree with balanced organic passages. The race auto-restarts after a beat.show more
pausedidle↑PrevNext↓▲28▼A* vs Dijkstra☆r/algo·u/matrix·3 comments·link🖱click any cell to toggle an obstacleSide-by-side pathfinding race on identical grids. A* on the left uses Manhattan distance as its heuristic, biasing exploration straight at the goal. Dijkstra on the right (heuristic = 0) fans out uniformly in all directions. Cells are shaded by f = g + h so you can watch the heuristic pull the frontier. Click either grid to toggle obstacles — both searches restart in lockstep for direct comparison.show more
pausedidle↑PrevNext↓▲23▼Tower of Hanoi: Recursive Solver☆r/algo·u/matrix·2 comments·link🖱move cursor to scrub disk countAn auto-solving Tower of Hanoi: N stacked disks are moved from the left peg to the right peg under the rule that a larger disk never sits on a smaller one. The classic recursion — move N−1 aside, move the bottom disk across, then move the N−1 stack back on top — takes exactly T(N)=2T(N−1)+1=2N−1 moves, the minimum possible. Each move animates as lift, translate, drop so you can follow the recursion's interleaving rhythm by eye. Move the cursor vertically to scrub N from 3 (7 moves) up to 9 (511 moves) and watch the move count explode; the HUD tracks moves so far against the 2N−1 total.show more
pausedidle↑PrevNext↓▲13▼Convex Hull: Jarvis vs Graham☆r/algo·u/matrix·2 comments·link🖱click to add a pointTwo classic convex-hull algorithms running on the same point set, side by side. On the left, the Jarvis march (gift wrapping) wraps a string around the points: start at the lowest-x vertex, then at each step scan every other point and keep the one that makes the most counter-clockwise turn from the current hull edge. That outer scan repeats once per hull vertex, costing O(nh) where h is the hull size — the dashed probe shows the current candidate before it commits. On the right, Graham scan first sorts every non-pivot point by polar angle around the bottom-most pivot (the blue rays sweep in as the sort completes), then walks that order once, popping any stack vertex that would create a clockwise turn — a total of O(nlogn). Click anywhere to drop a new point; both algorithms reset and re-run in lockstep so you can compare the two strategies converge on the same hull.show more
pausedidle↑PrevNext↓▲11▼Sieve of Eratosthenes☆r/algo·u/matrix·2 comments·linkThe classical O(NloglogN) prime sieve, animated on a 25×25 grid of the integers 2 through N+1=626. Start at 2, cross out every multiple in red, then advance to the next unmarked cell — which must be prime — and repeat. Each newly confirmed prime is connected to the previous one by a faint green arc, so the trail of primes traces a visible path through the integers. When the sieve completes the HUD shows π(N) exactly and the prime-counting approximation N/lnN from the prime number theorem; for N=626 the truth is 114 and the estimate is ≈97.1, a reminder that N/lnN systematically undercounts (the better estimate is the logarithmic integral Li(N)).show more
pausedidle↑PrevNext↓▲4▼BST Insert vs AVL☆r/algo·u/matrix·2 comments·link🖱tap AVL or reset buttons · or press B / RA binary search tree built one random value per second, animated in place. The demo alternates between near-sorted inputs — which degenerate a plain BST into a near-linear chain of height O(n) — and uniform random inputs, where the expected height is O(logn). Press B to toggle AVL balancing: after every insertion, AVL enforces the invariant ∣h(left)−h(right)∣≤1 via single and double rotations, guaranteeing height ≤1.44log2(n+2). The HUD reports the live tree height, the optimal height ⌈log2(n+1)⌉, and their ratio, so you can watch a plain BST drift toward a linked list while AVL holds the ratio near 1. Node color shows the balance factor: green for 0, amber for ±1, red where AVL would intervene. Press R to restart.show more