# Live graph algorithms

[Wiki](../README.md) / [Graph data science](README.md)

## Graph algorithms

These run **directly on the live graph** (no named projections). The illustrative
IDs below must be replaced with existing IDs from your database. Use
[application keys](../cypher/data-model.md#identity-and-id-reuse) to find nodes first. The
**direction** argument accepts `'OUT'`/`'OUTGOING'`, `'IN'`/`'INCOMING'`, or
anything else for both directions.

| Procedure | YIELD | Args |
|---|---|---|
| `gdb.dijkstra(sourceId, targetId, relType, weightProp, direction)` | `nodeIds, totalCost, path` | node ids (int), relationship type (string), weight property name (string; omit/empty → each hop costs 1), direction |
| `gdb.astar(sourceId, targetId, relType, weightProp, pointProp, direction)` | `nodeIds, totalCost, path` | as Dijkstra, plus `pointProp`: a `Point`, `Geometry` or `Geography` POINT property used for the straight-line heuristic. The heuristic is scaled to the cheapest cost per unit of distance over the relationship type, so weights in any unit stay exact; if some relationship's ends lack comparable locations it is plain Dijkstra. Shapes and scaling from version 1.6.2 |
| `gdb.pageRank(relType, iterations, dampingFactor)` | `nodeId, score` | type (string), iterations (int, default 20), damping (float, default 0.85) |
| `gdb.degree(nodeId, direction)` | `degree` | node id (int), direction |

```cypher
// shortest weighted path from node 0 to node 42 over :ROAD by 'km':
CALL gdb.dijkstra(0, 42, 'ROAD', 'km', 'OUT')
YIELD nodeIds, totalCost, path
RETURN nodeIds, totalCost;

// A* using a 'loc' point property as the heuristic:
CALL gdb.astar(0, 42, 'ROAD', 'km', 'loc', 'OUT') YIELD totalCost RETURN totalCost;

// PageRank over :LINKS, 30 iterations:
CALL gdb.pageRank('LINKS', 30, 0.85) YIELD nodeId, score
RETURN nodeId, score ORDER BY score DESC LIMIT 10;

CALL gdb.degree(0, 'OUT') YIELD degree RETURN degree;
```

> Cypher also offers `shortestPath`/`allShortestPaths` for **unweighted** shortest
> paths inside a `MATCH` — see
> [Paths and shortest-path queries](../cypher/paths.md#graph-algorithms).

## Related articles

[Graph projections and catalogue](projections.md) · [GDS algorithms and execution modes](algorithms.md) · [GDS resources and cancellation](resources.md) · [Graph data science](README.md)
