Default Algorithm (BFS) using ::ShortestPath
Notes:
- Breadth-first search finds the minimum number of hops between nodes along a specific edge type.
- This is the default algorithm for backward compatibility.
Syntax
Breadth-first Search Algorithm using ::ShortestPathBFS
Syntax
Dijkstra’s Algorithm using ::ShortestPathDijkstra
Notes:
- Dijkstra’s algorithm finds the path with minimum total weight by summing edge weights.
- Requires specifying which edge property to use as weight.
- Edge weights must be numeric (integers or floats) and non-negative.
Syntax
Return Type for Shortest Path Algorithms
The shortest-path result is an array of tuples because multiple equally short routes can be returned.Algorithm Selection Rules
| Algorithm | Use Case | Optimizes For | Edge Weights |
|---|---|---|---|
ShortestPath (BFS) | Social networks, network hops, simple routing | Minimum number of edges/hops | Ignored |
ShortestPathBFS | Same as above (explicit) | Minimum number of edges/hops | Ignored |
ShortestPathDijkstras | GPS routing, cost optimization, weighted graphs | Minimum total weight/cost | Required |
Examples
Example 1: BFS vs Dijkstra comparison
Consider this graph:BFSwill chooseA -> B(1 hop, shorter path by hop count).Dijkstrawill chooseA -> C -> B(70km total, shorter path by weight).
Example 2: Finding routes between locations
- Schema:
- Query:
- cURL:
- Python SDK:
- TypeScript SDK: