Skip to main content

Shortest Path Algorithms

HelixDB provides multiple algorithms for finding shortest paths between nodes:

::ShortestPath (BFS - Default)

Breadth-first search finds the minimum number of hops between nodes along a specific edge type. This is the default algorithm for backward compatibility.

::ShortestPathBFS (Explicit BFS)

Explicitly use breadth-first search to find the path with minimum hops.

::ShortestPathDijkstras (Weighted)

Dijkstraโ€™s algorithm finds the path with minimum total weight by summing edge weights. Requires specifying which edge property to use as weight.
Note: Edge weights must be numeric (integers or floats) and non-negative. Future Enhancement: In upcoming releases, you will be able to specify custom formulas for weight calculation instead of just property names. This will enable complex weighting based on traversals, calculations, or combinations of multiple properties.

Algorithm Selection

Choose the appropriate algorithm based on your use case:

Examples

Example 1: BFS vs Dijkstra comparison

This example demonstrates the difference between BFS (minimum hops) and Dijkstraโ€™s algorithm (minimum weight).
Consider this graph:
  • City A โ†’ City B (distance: 100km, 1 hop)
  • City A โ†’ City C โ†’ City B (distance: 30km + 40km = 70km, 2 hops)
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


Return Type

The shortest-path result is an array of tuples because multiple equally short routes can be returned.