cifrivo.

Computer science / GraphsAt your own pace

Find the path.
Understand every decision.

BFS, DFS, Dijkstra and A* on the same graph. Follow the search and discover what choosing the best path means.

BFS

Fewest connections first.

Undirected graph · 8 nodes
Undirected graph. Connection labels are their costs. Start: A. Goal: H. Current node: —. 86822225234ASTARTBCDEFGHGOAL
CurrentFrontierVisitedFound path

Start at the source. Advance to see how the next node is chosen.

Queue · next on the left
A
0 nodes selected

Finds a path with the fewest connections. When weights differ, that does not guarantee the lowest cost.

Change connections and costsTry your own cases

Saving updates an existing connection or creates a new one. Both directions have the same cost. Zero is allowed; negative costs are not.

  • A — B8
  • B — D6
  • D — H8
  • A — C2
  • C — E2
  • E — G2
  • G — H2
  • B — E5
  • D — F2
  • F — H3
  • E — F4
See costs and parentsState at this step
NodeConnectionsParent
A0—
B∞—
C∞—
D∞—
E∞—
F∞—
G∞—
H∞—
Compare all four algorithmsSame start and goal
Results of the complete run
AlgorithmPathConnectionsCostNodes
BFSA → B → D → H3227
DFSA → B → D → F → E → G → H6248
DijkstraA → C → E → G → H487
A*A → C → E → G → H485

Nodes = selections until reaching the goal or exhausting the search. This does not measure time. BFS minimizes connections; Dijkstra and A* minimize cost. DFS depends on neighbor order.

Try setting all costs to 1. Then add a short but expensive connection.