BFS traversal using cypher

穿精又带淫゛_ 提交于 2019-12-23 02:26:32

问题


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:


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?



来源:https://stackoverflow.com/questions/10182602/bfs-traversal-using-cypher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!