Neo4j All Pair Shortest Paths and Minimum Spanning Tree

Find the shortest path between nodes D and C based on the number of hops (ignore direction)

 
  match(l:location{name:'D'})-[d:distance]-(l1:location{name:'C'}),p=shortestpath((l)-[:distance]-(l1)) return p

Shortest Path Weighted

 
  Determine the weighted shortest path between A and E (ignore directions)

  match(l:location{name:'A'}),(l1:location{name:'E'}) 
  call algo.shortestPath.stream(l,l1,"cost")
  yield nodeId,cost 
  return algo.getNodeById(nodeId).name,cost

All Pairs Shortest Path with Neo4j(Weighted)

 
  Displays weighted shortest paths between all pairs of nodes in the graph 

  call algo.allShortestPaths.stream("cost") 
  yield sourceNodeId,targetNodeId,distance 
  where sourceNodeId < targetNodeId
  return  
  algo.getNodeById(sourceNodeId).name,
  algo.getNodeById(targetNodeId).name,distance 
  order by distance

Minimum Spanning Tree Query

 
  match(l:location{name:'A'}) 
  call algo.spanningTree.minimum("location","distance","cost",id(l)) 
  yield loadMillis,computeMillis,effectiveNodeCount 
  return loadMillis,computeMillis,effectiveNodeCount