[[graphalgo]]
Graph Algorithms
================

Neo4j graph algorithms is a component that contains Neo4j implementations of some common algorithms for graphs.
It includes algorithms like:

* Shortest paths,
* all paths,
* all simple paths,
* Dijkstra and
* A*.

[[graph-algo-introduction]]
== Introduction ==

The graph algorithms are found in the +neo4j-graph-algo+ component, which is included in the standard Neo4j download.

* Javadocs: http://components.neo4j.org/neo4j/{neo4j-version}/apidocs/org/neo4j/graphalgo/package-summary.html
* Separate download: http://repo1.maven.org/maven2/org/neo4j/neo4j-graph-algo/{neo4j-version}
* Source code: https://github.com/neo4j/graphdb/tree/master/graph-algo

For Maven users, the component has the coordinates +org.neo4j:neo4j-graph-algo+ and should be used with the same version of +org.neo4j:neo4j-kernel+.
Different versions of the graph-algo and kernel components are not compatible in the general case.
Both components are included transitively by the +org.neo4j:neo4j:pom+ artifact which makes it simple to keep the versions in sync.

== Path finding examples ==

Calculating the shortest path (least number of relationships) between two nodes:

[snippet,java]
----
component=neo4j-graph-algo
source=examples/PathFindingExamplesTest.java
tag=createIndices
----

Using Dijkstra to calculate cheapest path between node A and B where each relationship can have a weight (i.e. cost) and the path(s) with least cost are found.

[snippet,java]
----
component=neo4j-graph-algo
source=examples/PathFindingExamplesTest.java
tag=dijkstraUsage
----

Using A* to calculate the cheapest path between node A and B, where cheapest is f.ex. the path in a network of roads which has the shortest length between node A and B.

[snippet,java]
----
component=neo4j-graph-algo
source=examples/PathFindingExamplesTest.java
tag=astarUsage
----


///////////////////



Other algos

	There are other algorithms which can be used on smaller graphs, f.ex. calculating
	centrality, betweeness, closeness, eccentrity and more. Those algos aren't designed
	to scale to very big graphs, but can still be useful in some scenarios. They reside in the
	<<org.neo4j.graphalgo.impl.centrality>> package.

///////////////////

