Shortest Path Algorithms in Helix Â
Helix provides three powerful algorithms for finding shortest paths between nodes in your graph. Each algorithm is optimized for different use cases and graph characteristics.Available Algorithms
BFS
Unweighted shortest paths using breadth-first search
Dijkstra
Weighted shortest paths with custom weight calculations
A*
Heuristic-guided weighted shortest paths
Algorithm Comparison
| Algorithm | Best For | Graph Type | Complexity | Customizable Weights |
|---|---|---|---|---|
| BFS | Hop count minimization | Unweighted | O(V + E) | No |
| Dijkstra | Flexible weight calculations | Weighted | O((V + E) log V) | Yes |
| A* | Goal-directed search | Weighted + Heuristic | O((V + E) log V) | Yes |
All algorithms guarantee finding the optimal shortest path when used correctly. A* can be significantly faster than Dijkstra when a good heuristic is available.
When to Use Each Algorithm
Use BFS When:
- All edges have equal weight (or no weight)
- You want to minimize hop count
- Finding social network distances
- Analyzing friend-of-friend relationships
- Simple connectivity analysis
Use Dijkstra When:
- Edges have different weights (distance, cost, time, etc.)
- You need custom weight calculations using properties
- Combining multiple factors into path weights
- No directional heuristic is available
- Maximum flexibility is needed
Use A* When:
- You have a goal-directed heuristic (e.g., geographic distance)
- Graph has spatial properties
- Need faster performance for long paths
- Heuristic can guide the search effectively
Quick Examples
BFS: Unweighted Path
Dijkstra: Weighted Path
A*: Heuristic-Guided Path
Custom Weight Expressions
Both Dijkstra and A* support sophisticated weight calculations that can reference:- Edge properties:
_::{property_name}- Properties on the edge itself - Source node:
_::FromN::{property_name}- Properties from the edge’s starting node - Destination node:
_::ToN::{property_name}- Properties from the edge’s ending node - Mathematical operations: Combine properties with functions like ADD, MUL, POW, etc.
Example: Traffic-Aware Routing
Example: Multi-Factor Scoring
When using custom weights, ensure all weight values are non-negative. Negative weights can lead to incorrect results or infinite loops.
Path Result Structure
All shortest path algorithms return the same result structure:Performance Considerations
- BFS: Fastest for unweighted graphs, memory efficient
- Dijkstra: Moderate performance, very flexible
- A*: Can be much faster than Dijkstra with a good heuristic, but requires additional node property for heuristic
Tips for Optimal Performance:
- Use BFS when weights aren’t needed
- Index properties used in weight calculations
- For A*, ensure heuristic is admissible (never overestimates)
- Consider graph density when choosing algorithms