Skip to main content
@tags: shortest-path, algorithms, bfs, dijkstra, pathfinding, graph-algorithms

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

Examples

Example 1: BFS vs Dijkstra comparison

Consider this graph:
  • BFS will choose A -> B (1 hop, shorter path by hop count).
  • Dijkstra will choose A -> C -> B (70km total, shorter path by weight).

Example 2: Finding routes between locations

  • Schema:
  • Query:
  • cURL:
  • Python SDK:
  • TypeScript SDK: