A logbook for curious waters

Find a way through

Same map, six ways to search. Step through an algorithm, then switch to another to see what changes. Select a node to change the destination; select a connection to edit its weight.

Fewest edgesStep 1
UndiscoveredWaitingExploredCurrentFinal path

Explored 0Connections examined 0Waiting 1
Edit the graph

Select a connection in the map to edit it. Select any node to make it the destination. The dropdowns also work with a keyboard.

What are we solving?

A graph is a collection of nodes (the labeled circles) and edges (their connections). Here, each edge has a positive weight representing travel cost. We want a route from a starting node to a destination.

AlgorithmChooses next node byFinds
Breadth-first searchDiscovery orderFewest edges
DijkstraLowest cost so farLowest total weight
A*Lowest cost so far + estimate remainingLowest total weight with the safe estimate used here
Depth-first searchOne unvisited neighbor at a time; backtrack on exhaustionA path, without a shortest-path guarantee
Bidirectional BFSAlternating complete layers from both endsFewest edges
Greedy best-firstLowest remaining estimate onlyA path, without a cheapest-path guarantee

Explore the lessons

A revealing experiment

Add an A–I connection and set its weight to 99. Breadth-first search chooses that single connection. Dijkstra and A* take a longer route with a lower total cost. Greedy search chooses the expensive shortcut because its remaining estimate is zero. Then choose “Equal costs” to see why breadth-first search works well when every move costs the same.

Try the “Unreachable destination” map to watch a search exhaust its frontier. Or set the start and destination to the same node: the solution needs no connections.