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.

Sieve of EratosthenesAn ancient, elegant way to find every prime up to n: list the numbers, then repeatedly take the next uncrossed one and strike out all its multiples.Euclid's GCDThe greatest common divisor of a and b, seen as geometry: the side of the largest square that tiles an a×b rectangle with no gaps.Euler's totient sieveφ(n) counts how many integers from 1 to n share no common factor with n. A sieve fills in every φ at once.Pascal's triangleEach entry is the sum of the two directly above it; the edges are 1. Row n lists the binomial coefficients C(n,0..n).Collatz conjecture (3n+1)From n, halve it if even, otherwise 3n+1. The unproven conjecture: you always eventually reach 1.Continued fractionWrite a/b as a₀ + 1/(a₁ + 1/(a₂ + …)). The terms are exactly the quotients of Euclid's algorithm.Prime factorization (factor tree)Repeatedly split a number into its smallest prime factor and the rest, until only primes remain at the leaves.Sieve of SundaramFinds all primes up to n by marking composite-generating pairs i+j+2ij, leaving the rest as primes.Linear sieve (SPF)Sieves primes and records the smallest prime factor of every composite in true O(n) time.Divisor count τ(n)Computes the number of divisors of every integer 2..n by adding 1 to each multiple of every d.Aliquot sum classificationClassifies each number 2..n as perfect, abundant, or deficient based on the sum of its proper divisors.Happy numbersDetermines which numbers 2..n are happy — their iterated digit-square-sum eventually reaches 1.Squarefree sieveMarks each number 2..n squarefree (no p² divides it) or non-squarefree using a sieve over prime squares.Divisors of nTrial-divides each d from 1 to n, highlighting exactly the divisors of n in green.Figurate numbersMarks triangular, square, and pentagonal numbers in 1..n with distinct colours by walking index k.Collatz stopping timesColours each m in 2..n by how many Collatz steps it takes to reach 1, creating a heatmap.Goldbach's conjectureFinds the first Goldbach partition of (the largest even ≤ n) as a sum of two primes, scanning upward.Pascal's triangle mod 2 (Sierpinski)Pascal's triangle reduced modulo 2, revealing the self-similar Sierpinski triangle fractal.Catalan's triangleA number triangle whose diagonal entries are the famous Catalan numbers 1, 1, 2, 5, 14, 42, ...Stirling numbers (2nd kind)S(n,k) counts the number of ways to partition a set of n elements into exactly k non-empty subsets.Bell triangleAitken's Bell triangle is a simple array whose left edge produces the Bell numbers 1, 1, 2, 5, 15, 52, ...Eulerian numbersA(n,k) counts permutations of 1…n that have exactly k ascents (positions where the next element is larger).Digital rootRepeatedly sum the decimal digits of n until a single digit remains — that digit is the digital root.Happy number traceReplace n repeatedly by the sum of the squares of its digits; stop when you reach 1 (happy) or revisit a value (unhappy).Look-and-say sequenceRead each term aloud — runs of equal digits become their count followed by the digit — to produce the next term.Recaman's sequencea(0)=0; each a(k) steps k backwards if the result is positive and new, otherwise k forwards.Factorial sequenceBuilds the sequence 0!, 1!, 2!, …, n! by multiplying each new term by its index.Powers of twoBuilds the sequence 2⁰, 2¹, 2², …, 2ⁿ by doubling each term.Farey sequenceLists every reduced fraction in [0, 1] with denominator ≤ n in ascending order.Least common multipleFind the smallest positive integer divisible by both a and b by walking multiples of the larger value.Base conversionConvert the integer a into the number system with base b (clamped to 2–16) by repeatedly extracting remainders.Josephus problemSimulate a circle of n people eliminating every k-th person until one survivor remains.