本文介绍了使用密码进行BFS遍历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用BFS遍历有向无环图(DAG).我正在通过REST API使用neo4j,因此与neo4j进行通讯的主要方式是使用Cypher.

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.

使用Cypher,我可以从起始节点检索所有路径的集合,并从中得出BFS遍历.

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

我想知道是否有使用Cypher进行BFS遍历的更简单方法.我期望的输出将是一组节点集.

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.

推荐答案

您难道不可以只按长度排序生成的路径,也许取每个路径的最后一个节点,例如 http://bit.ly/HF0p0t 喜欢

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

要按升序返回路径?

这篇关于使用密码进行BFS遍历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 19:31