1

I need to traverse a directed acyclic graph (DAG) using BFS. I am using neo4j via REST API, so my main way of commuication with neo4j is using Cypher.

With Cypher I can retrieve a set of all the paths from a starting node, and from them derive a BFS traversal.

I was wondering if there's a simpler way of getting a BFS traversal using Cypher. What I expect as output would be an array of sets of nodes.

Dan
  • 1,163
  • 14
  • 34
  • I'd love to help, but I don't quite understand what it is you are trying to accomplish. A bit more information would be helpful. – Andres Apr 17 '12 at 10:14
  • @Andres: ultimately I would like to have as output the traversal of a BFS iterator over the graph, ordered by depth. – Dan Apr 17 '12 at 10:52
  • Couldn't you then just order resulting paths after length, maybe take the last node from each, like http://bit.ly/ItCCQY – Peter Neubauer Apr 17 '12 at 12:21

1 Answers1

1

Couldn't you then just order resulting paths after length, maybe take the last node from each, like http://bit.ly/HF0p0t like

start n=node(1) match p = n-[*1..]->m return p, length(p), last(p) order by length(p) asc

To get back the paths in ascending order?

Peter Neubauer
  • 6,311
  • 1
  • 21
  • 24
  • a great starting point, thanks! now I just need to figure out how to traverse edges of a given type and I'm good to go.... +1 for the console; wasn't aware it's there... – Dan Apr 18 '12 at 10:26
  • i'm getting a SyntaxException: unknown function when I use last(p). I have version 1.6.1. is that too old? what version would you recommend I install? – Dan Apr 18 '12 at 17:25
  • 1
    Yes, this is Neo4j 1.7, I think these functions were not in 1.6 – Peter Neubauer Apr 20 '12 at 21:45