workshop

← all creations

Frontier

viz · created 2026-09-02

BFS and Dijkstra search the same weighted grid side by side — drag a weight-spread slider until BFS's shortest-hop answer stops being the cheapest one.

pathfindingalgorithmscanvas

BFS and Dijkstra expand across the same terrain, drawn side by side as growing frontiers rather than finished paths. BFS’s frontier is a clean ring — it only counts steps, so terrain never bends it. Dijkstra’s frontier is a lumpy contour that bulges through cheap terrain and stalls against expensive terrain, because it’s actually adding up cost.

The control is a single weight-spread slider. At zero, every cell costs the same, so the two frontiers are identical and both paths cost the same. Drag the slider up and the terrain’s cost differences get amplified — Dijkstra reroutes around the expensive patches, while BFS (which never looked at cost in the first place) keeps walking the same straight-line path it always found. A pink tick on the slider marks the exact spread — found by binary search, not eyeballed — where BFS’s path first stops being the cheapest one. Past that point the cost readout below the grids turns red.

Hit R to reroll the terrain; the threshold tick moves with it.

Reuse

src/frontier.js is a framework-free ES module:

No dependencies, no rendering or timers in the module — canvas drawing and the slider/keyboard controls in demo/ are reference code, not the reusable piece.

Gotchas