algo·visual

36 algorithms · step through every line

See algorithms think.

Watch every comparison, swap and pointer move as an animation you can pause and rewind, with the real source code highlighted line by line as it runs.

Sorting

Put things in order and watch every comparison and swap.

Searching

Find a target by scanning, halving, or jumping ahead.

Data Structures

Lists, stacks, queues, hash tables, trees and heaps, op by op.

Graphs

Traversals, shortest paths and spanning trees on grids and networks.

BFS (Grid)

O(V + E)

Breadth-first search spreads out from the start one ring at a time using a FIFO queue, so cells are reached in order of their distance in moves.

DFS (Grid)

O(V + E)

Depth-first search keeps going in one direction (up first, then right, down and left) and only backtracks to the most recent unexplored cell on its stack when it hits a dead end.

Dijkstra (Grid)

O((V + E) log V)

Dijkstra's algorithm always expands the open cell with the smallest known distance, so on a weighted grid it finds the cheapest path rather than the one with fewest moves.

A* Search

O((V + E) log V)

A* is Dijkstra's algorithm steered by a heuristic: it expands the cell with the smallest f = g + h, where g is the cost so far and h is the Manhattan distance still to go.

BFS (Graph)

O(V + E)

Breadth-first search visits the source, then all of its neighbours, then their unseen neighbours, using a FIFO queue.

DFS (Graph)

O(V + E)

Depth-first search follows one branch as deep as it can before backing up to the most recent node that still has an unexplored neighbour.

Dijkstra (Graph)

O(V²)

Dijkstra's algorithm grows a set of settled nodes outward from the source, always settling the unfinished node with the smallest tentative distance and then relaxing its edges.

Topological Sort

O(V + E)

Kahn's algorithm orders a directed acyclic graph so every edge points forward: it repeatedly outputs a node with no remaining incoming edges and deletes that node's outgoing edges.

Prim's MST

O(V²)

Prim's algorithm grows a minimum spanning tree from a single node, each round adding the cheapest edge that connects the tree to a node outside it.

Kruskal's MST

O(E log E)

Kruskal's algorithm considers edges from lightest to heaviest and keeps each one that joins two different components, skipping any edge that would close a cycle.

Dynamic Programming

Fill the table one subproblem at a time.

Search algorithms

Jump to any algorithm or page