Watch Dijkstra, A*, greedy best-first, BFS, DFS and bidirectional search find a route across real city streets. Pick the city, the start and the destination, and compare the searches side by side.
Pick a city, where you start and where you're going, and the searches to run. Watch them find the best route on real streets.
About this algorithm
A street map is a graph: every junction is a node and every street between two junctions is an edge, weighted by its length. Finding a route is a shortest-path search on that graph. This page runs six searches on real city streets imported from OpenStreetMap, so you can watch how differently they spread out before reaching the same destination, or a worse one.
Use it to see why route planners do not use the textbook searches as they are. Dijkstra is the correct baseline, A* is what a maps app builds on, and the others show what goes wrong without a cost rule or a sense of direction. For the mechanics on a small graph you can follow edge by edge, start with the Dijkstra, BFS and DFS pages in this module, then come back here to see the same rules on thousands of junctions.
Choose one of the cities, then a start and a destination from its popular places, or tap the map to drop either end on the nearest junction. Random route picks two places far enough apart that the search has a city to cross.
One search runs on a full-size map. Turn on Compare to run two to six on the same map with the same ends: up to four side by side on one clock, or one after another.
Every road a search explores lights up in its colour, and the count beside it climbs. Dijkstra settles the nearest unfinished junction next, so it grows in rings. A* adds the straight-line distance still to go, so it leans towards the destination. Greedy uses only that distance, BFS counts junctions instead of kilometres, DFS dives down one street at a time, and Both ends runs Dijkstra from the start and the destination at once.
When a search reaches the destination it traces its route back through the parent of each junction, and the route length appears in kilometres. Compare the counts and the lengths: a search that explored far fewer roads but drew a longer route took a shortcut that cost the traveller.
On Mumbai's whole official area, about 4,500 junctions, Dijkstra explores 6,598 roads and finds a 20.9 km route. A* finds the same 20.9 km route after only 744 roads, because the straight-line distance keeps it heading south along the coast. Searching from both ends finds that route too, after 4,025 roads. Greedy reaches the Gateway after just 69 roads, but its route is 23.0 km: it never checks what the streets cost, only how close each step looks. BFS returns 22.8 km, the route with the fewest junctions rather than the fewest kilometres. DFS wanders the island and comes back with a 150 km route, which is why nobody gives directions with it.
The straight-line distance to the destination can never be longer than any real road route to it. A guess that never overestimates is called admissible, and with one A* still returns the shortest route while exploring far fewer roads than Dijkstra.
Time: Dijkstra and A* take each junction off a binary heap once and push each street at most once, so O((V + E) log V); BFS and DFS skip the heap, O(V + E), and A* is usually far faster than its worst case. Space: one distance, one parent and one visited flag per junction, plus the heap or queue of junctions waiting.