Loading…
Play, pause, and step through classic algorithms — with real source code in multiple languages, right in your browser.
Repeatedly steps through the list, swapping adjacent out-of-order pairs so the largest values 'bubble' to the end.
Finds the minimum of the unsorted region on each pass and places it at the front.
Builds the sorted array one item at a time by inserting each new element into its correct place among the already-sorted prefix.
Divide and conquer: pick a pivot, partition values around it, then recursively sort each side.
Divide and conquer: split the array in half, sort each half, then merge the two sorted halves.
Builds a max-heap, then repeatedly swaps the root (largest) to the end and restores the heap — in-place and O(n log n) in every case.
A gap-based generalization of insertion sort: sort elements far apart first, shrinking the gap until it becomes a final pass of ordinary insertion sort.
A bidirectional bubble sort: each round bubbles the largest to the right, then the smallest to the left, closing in from both ends.
Checks each element in turn until the target is found or the array ends. Works on any array, sorted or not.
On a sorted array, repeatedly halves the search range by comparing the middle element to the target — O(log n).
On a sorted array, jumps ahead by fixed blocks of √n until it passes the target, then scans the last block linearly.
Like binary search, but estimates the probe position from the target's value — near O(log log n) on uniformly distributed data.
Doubles an index bound until it overshoots the target, then binary-searches the found range — great for unbounded or very large sorted inputs.
Explores the grid in expanding rings from the start, guaranteeing the fewest-steps path on an unweighted grid.
Plunges as deep as possible along one branch before backtracking. Finds a path, but not necessarily the shortest.
Expands the closest unsettled node first using a priority queue, giving the shortest path even when cells have different costs (weights).
Like Dijkstra, but a heuristic pulls the search toward the goal — so it settles far fewer cells while still finding the shortest path.
Always expands the node that looks closest to the goal by heuristic alone. Very fast and targeted, but its path is not guaranteed to be shortest.
Fills a table where dp[i][j] is the LCS length of the first i and j characters — each cell built from its diagonal, top, or left neighbour.
The Levenshtein distance: the minimum number of insertions, deletions, or substitutions to turn one string into another, built cell by cell.
Visits Left → Node → Right. On a binary search tree this yields the values in sorted order.
Visits Node → Left → Right. Useful for copying a tree or serialising its structure.
Visits Left → Right → Node. Children are processed before their parent — handy for deleting or evaluating a tree.
Breadth-first: visits the tree one level at a time, left to right, using a queue.
Walks down from the root, going left or right by comparing the target to each node — O(log n) on a balanced tree.
Places N queens on an N×N board so none share a row, column, or diagonal — trying columns row by row and backtracking on conflict.
The classic recursion puzzle: move a stack of disks to another peg, never placing a larger disk on a smaller one. Solves in 2ⁿ − 1 moves.