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.
Linear searchLinear search scans the array left to right, comparing each element with the target until it finds it.Binary searchBinary search repeatedly halves a sorted array, comparing the middle element with the target.Jump searchJump search steps through a sorted array in fixed blocks, then scans linearly inside the block that may hold the target.Interpolation searchInterpolation search guesses where the target likely is by interpolating between the range's endpoints — fast on uniform data.Exponential searchExponential search doubles an index until it passes the target, then binary-searches the bracketed range.Ternary searchTernary search splits a sorted array into thirds, probing two points each step to discard two-thirds of what's left.Fibonacci searchFibonacci search narrows a sorted array using Fibonacci numbers — only addition and subtraction, no division.
Selection
Find the k-th smallest value.
Data structures
How data is stored, added, and removed.
Stack (LIFO)A stack is a last-in, first-out (LIFO) structure: push adds to the top, pop removes the top.Queue (FIFO)A queue is a first-in, first-out (FIFO) structure: enqueue adds to the back, dequeue removes from the front.DequeA deque (double-ended queue) allows adding and removing from both ends.Binary search treeA binary search tree keeps values ordered: everything left of a node is smaller, everything right is larger — so lookups follow one path down.Binary heap (min)A binary min-heap keeps the smallest value at the root; insert bubbles a value up and extract-min sinks the new root down.Linked listA linked list chains nodes together with pointers — O(1) to add at the head, but you must walk the chain to find anything.Hash tableA hash table maps each value to a bucket via a hash function, giving average O(1) lookup; collisions share a bucket as a chain.
Tree algorithms
Walk a tree, node by node.
In-order traversalIn-order traversal visits the left subtree, then the node, then the right subtree — on a BST that yields sorted order.Pre-order traversalPre-order traversal visits the node first, then its left and right subtrees — handy for copying or serializing a tree.Post-order traversalPost-order traversal visits both subtrees first, then the node — handy for deleting or evaluating a tree.Level-order traversalLevel-order traversal visits the tree top to bottom, left to right — it's breadth-first search on a tree, using a queue.
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.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.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.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.
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.