Overview
Pathfinding
BFS, Dijkstra, A* — graph routing built into the database.
Why it matters
Pathfinding is the canonical first GDS algorithm — once you can compute shortest paths inside the DB you can answer routing, supply-chain and fraud questions without exporting.
Going deeper
Pick by what 'shortest' means and what you know:
| Algorithm | Minimizes | Needs |
|---|---|---|
| BFS | Number of hops | Unweighted graph |
| Dijkstra | Sum of edge weights | Non-negative weights |
| A* | Weighted cost, faster | A good admissible heuristic (e.g. straight-line distance) |
MATCH (a:Stop {name:$from}), (b:Stop {name:$to})
CALL gds.shortestPath.dijkstra.stream('transit', {
sourceNode: a, targetNode: b, relationshipWeightProperty: 'minutes'
}) YIELD totalCost, nodeIds
RETURN totalCost;
Doing this inside the database answers routing, supply-chain and fraud questions without exporting the topology. A* only beats Dijkstra when you have a heuristic that never overestimates the remaining cost — otherwise it can return a wrong path.
