1
votes

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.

1
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
@Andres: ultimately I would like to have as output the traversal of a BFS iterator over the graph, ordered by depth.Dan
Couldn't you then just order resulting paths after length, maybe take the last node from each, like bit.ly/ItCCQYPeter Neubauer

1 Answers

1
votes

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?