Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Active BFS, DFS, and postorder generators snapshot graph structure when iteratio
| `getShortestPath(graph, { from, to, ... })` | One shortest path or `undefined` | sublinear in practice | `from` accepts a node ID or predicate. A predicate matching multiple nodes returns the globally shortest path; graph order breaks ties. Single-pair ID queries use **bidirectional Dijkstra** (frontiers meet long before a unidirectional search finishes). Pass `algorithm: 'bellman-ford'` for negative weights (full search). |
| `genShortestPaths(graph, opts?)` / `getShortestPaths(...)` | *All* tied shortest paths from `from` (to `to`, or to every reachable node) | Dijkstra O((n + m) log n) + lazy reconstruction | `from` accepts a node ID or predicate; predicates independently fan out from every matching node in graph order. Tie predecessors are recorded, so equal-cost alternatives are all yielded. With `to`, the search **early-exits** once everything at distance ≤ dist(target) settles. Paths are reconstructed on demand — abandoning the generator never pays for paths it didn't yield. Zero-weight cycles are handled (no revisits during reconstruction). |
| `getAStarPath(graph, { from, to, heuristic, ... })` | One heuristic-guided shortest path | O((n + m) log n), heuristic-dependent | `from` accepts a node ID or predicate. Multiple matches return the globally shortest path; graph order breaks ties. Heuristics must be finite; admissible heuristic ⇒ optimal path. |
| `getAllPairsShortestPaths(graph, opts?)` | Shortest paths between all pairs | Dijkstra-per-source (default) O(n(n + m) log n); `'floyd-warshall'` O(n³); `'bellman-ford'` O(n²m) | Floyd-Warshall throws on a negative cycle (self-distance < 0). Eager — output can be huge. |
| `genAllPairsShortestPaths(graph, opts?)` / `getAllPairsShortestPaths(...)` | Shortest paths between all ordered pairs | Dijkstra-per-source (default) O(n(n + m) log n); `'floyd-warshall'` O(n³); `'bellman-ford'` O(n²m) | Includes tied shortest paths. The generator supports early exit; the eager form can produce huge output. Floyd-Warshall throws on a negative cycle. |
| `genShortestSimplePaths(graph, opts)` / `getShortestSimplePaths(...)` | Loopless alternatives in nondecreasing weight order | Yen: O(K·n·(m + n log n)) for K results | `from` and `to` are required. `limit` bounds results; omitting it enumerates every simple path by cost. Non-negative weights only. |
| `genSimplePaths(graph, opts?)` / `getSimplePaths(...)` / `getSimplePath(...)` | All (or first) simple paths from `from` (optionally to `to`) | exponential (output-sensitive) | `from` accepts a node ID or predicate; predicates independently fan out from every matching node in graph order. DFS with backtracking; without `to`, every non-empty simple path is yielded. |
| `getJoinedPath(headPath, tailPath)` | Concatenated `GraphPath` | O(steps) | Throws unless head ends where tail starts. |
Expand Down
Loading