O(n) · visualised

Algorithm & data-structure visualizer

Watch classic algorithms and data structures run step by step. Pick one to start.

Sorting algorithms

Watch arrays sort themselves, step by step.

Bubble sortBubble sort repeatedly swaps adjacent out-of-order elements, letting the largest "bubble" to the end each pass.Insertion sortInsertion sort builds the sorted array one item at a time, inserting each new element into its place among the earlier ones.Selection sortSelection sort repeatedly finds the smallest remaining element and moves it to the front.Merge sortMerge sort splits the array in half, sorts each half, then merges the two sorted halves together.Quick sortQuick sort picks a pivot, partitions the array around it, then sorts the two sides.Heap sortHeap sort builds a max-heap, then repeatedly moves the largest element to the end.Shell sortShell sort is insertion sort that first compares far-apart elements, shrinking the gap each round.Cocktail sortCocktail sort is bubble sort that sweeps both ways — bubbling the largest up and the smallest down each round.Comb sortComb sort is bubble sort that compares elements a large gap apart, shrinking the gap toward 1.Gnome sortGnome sort steps forward while order is correct and swaps backward when it isn't.Odd-even sortOdd-even sort compares fixed pairs — first the odd-indexed pairs, then the even ones — repeating until none are out of order.Pancake sortPancake sort sorts using only prefix flips: bring the largest value to the front, then flip it down to its place.Cycle sortCycle sort places each value directly into its final spot, making the theoretical minimum number of writes.Stooge sortStooge sort is a recursive curiosity: sort the first 2/3, then the last 2/3, then the first 2/3 again.Counting sortCounting sort doesn't compare elements — it tallies how many of each value there are, then writes them back out in order. Linear time when the value range is small.Radix sortRadix sort sorts numbers one digit at a time, least-significant first, using a stable bucket pass for each digit. No comparisons needed.

Searching

Find a value in an array.

String matching

Find a pattern inside a text.

Selection

Find the k-th smallest value.

Data structures

How data is stored, added, and removed.

Tree algorithms

Walk a tree, node by node.

Graph algorithms

Traversing nodes and edges.

BFSBreadth-first search explores a graph level by level using a FIFO queue.DFSDepth-first search explores as far as possible down each branch before backtracking, using a stack.Iterative-deepening DFSIterative-deepening DFS runs a depth-limited DFS over and over, raising the limit each round — getting BFS's level-by-level reach with DFS's tiny memory.Dijkstra (shortest path)Dijkstra finds the shortest path from a start node by always expanding the closest unvisited node — here edge cost is the distance between nodes.Prim's MSTPrim grows a minimum spanning tree from a start node, always adding the cheapest edge that reaches a new node.Kruskal's MSTKruskal builds a minimum spanning tree by adding edges from cheapest to most expensive, skipping any that would form a cycle.Borůvka's MSTBorůvka builds a minimum spanning tree in rounds: every component grabs its own cheapest outgoing edge at once, so the forest merges quickly in parallel.Bellman-FordBellman-Ford finds shortest paths by relaxing every edge V-1 times — slower than Dijkstra, but it handles negative edge weights.Topological sortA topological sort lines up the vertices of a directed acyclic graph so every edge points forward — a valid order to do tasks that depend on each other.Floyd-WarshallFloyd-Warshall finds the shortest distance between every pair of vertices at once, by repeatedly asking whether routing through one more vertex is shorter.Strongly connected componentsAn SCC is a group of vertices that can all reach each other. Kosaraju's algorithm finds them with two depth-first passes — one on the graph, one on its reverse.Maximum flowHow much can flow from a source to a sink through a network of capacitated pipes? Edmonds-Karp finds out by repeatedly pushing flow along the shortest path with spare room.Articulation points & bridgesAn articulation point is a vertex whose removal splits the graph; a bridge is such an edge. Tarjan finds both in one DFS by tracking how far back each subtree can reach.Connected componentsConnected components are the separate "islands" of a graph — maximal groups of vertices reachable from one another. A flood-fill colours each one.Bipartite checkA graph is bipartite if its vertices split into two groups with every edge crossing between them — checked by 2-colouring with BFS.Cycle detectionCycle detection asks whether an undirected graph contains a loop — DFS finds one the moment it meets a back edge to an earlier vertex.

Grid pathfinding

Route through a maze of walls.

BFS pathfindingBreadth-first search explores a grid in rings of equal distance, so the first time it reaches the goal it has found the shortest path — but it fans out in every direction.A* pathfindingA* is BFS with a sense of direction: it always expands the cell with the best estimated total cost, so it heads toward the goal and explores far fewer cells.Greedy best-firstGreedy best-first search always heads for the cell that looks closest to the goal. It's fast and direct, but it can be fooled into a longer, non-optimal path.Bidirectional searchBidirectional search runs two BFS waves at once — one from the start, one from the goal — and stops where they meet, exploring far fewer cells than a single search.Dijkstra (weighted grid)Dijkstra on a grid where cells cost different amounts to enter finds the cheapest route — which may wind around costly terrain instead of taking the fewest steps.Maze generationThe recursive backtracker carves a maze with a randomized depth-first walk — burrowing forward, knocking out walls, and backing up at dead ends until every cell is reached.Flood fillFlood fill is the paint bucket: from one cell it spreads outward to every connected open cell, stopping at walls — filling a whole region in one sweep.Maze — PrimRandomized Prim's grows a maze outward from a seed: it keeps a frontier of rooms next to the maze and keeps connecting a random one until every room is in.Maze — WilsonWilson's algorithm carves a maze with loop-erased random walks — wandering from unvisited rooms until they hit the maze — so every possible maze is equally likely.

Dynamic programming

Fill a table, reuse subproblems.

Edit distanceEdit distance (Levenshtein) is the fewest single-character inserts, deletes, and substitutions to turn one string into another — built up in a table.Longest common subsequenceThe longest common subsequence is the longest sequence of characters appearing in both strings in the same order, not necessarily adjacent — found with a DP table.Coin changeCoin change finds the fewest coins that add up to a target amount, with an unlimited supply of each denomination — built up in a table, amount by amount.Subset sumSubset sum asks whether any subset of a set of numbers adds up to a target — a table marks each (number, sum) reachable or not.Longest increasing subsequenceThe longest increasing subsequence is the longest run of values that increases left to right, picking elements in order but not necessarily adjacent.0/1 Knapsack0/1 knapsack picks the most valuable set of items that fits a weight budget — each item taken whole or not at all — filled in capacity by capacity.Unbounded knapsackUnbounded knapsack maximizes value within a weight budget when each item can be taken any number of times — so the best column to the left feeds the same row.PartitionThe partition problem asks whether a set of numbers can be split into two groups with equal sums — true only if the total is even and some subset reaches half of it.Kadane's max subarrayKadane's algorithm finds the largest sum of any contiguous slice in one pass — extending a running window, and abandoning it the moment its sum turns negative.Fibonacci (DP)The Fibonacci sequence built bottom-up: each term is the sum of the previous two, filling a one-row table left to right in linear time.

Computational geometry

Shapes and points in the plane.

Number theory

Primes, divisors, and number tricks.