【发布时间】:2017-07-13 00:48:32
【问题描述】:
我对 Neo4j 还很陌生,正在考虑将其用作解决方案。考虑这个例子:Finding the Shortest Path through the Park
Neo4j 中 REDUCE 函数的大 O 表示法是什么?它是计算每种可能性并对它们进行排名还是更有效?
【问题讨论】:
标签: neo4j reduce shortest-path bigdata
我对 Neo4j 还很陌生,正在考虑将其用作解决方案。考虑这个例子:Finding the Shortest Path through the Park
Neo4j 中 REDUCE 函数的大 O 表示法是什么?它是计算每种可能性并对它们进行排名还是更有效?
【问题讨论】:
标签: neo4j reduce shortest-path bigdata
REDUCE 函数简单地遍历集合中的项目,为每个项目执行返回值的任意操作,保留最新值,并最终返回最后一个值。
如果我们忽略“任意操作”本身的复杂度,REDUCE函数的复杂度是O(N),其中N是集合的大小。
【讨论】:
REDUCE。
如果你指的是这个查询
START startNode=node:node_auto_index(name="Start"),
endNode=node:node_auto_index(name="Finish")
MATCH p=(startNode)-[:NAVIGATE_TO*]->(endNode)
RETURN p AS shortestPath,
reduce(distance=0, r in relationships(p) : distance+r.distance) AS totalDistance
ORDER BY totalDistance ASC
LIMIT 1;
首先你定义你的开始和结束节点......并匹配它们之间的所有路径......
RETURN p AS shortestPath,
reduce(distance=0, r in relationships(p) : distance+r.distance) AS totalDistance
ORDER BY totalDistance ASC
LIMIT 1;
这个reduce 是这样工作的,它从路径的关系中提取所有距离属性并将它们总结起来。因此,如果您 order by 结果按距离递增,而 limit 结果为 1,您只会得到第一个最小距离
附言我认为您所指的大 O 实际上是零 0,因此它从零开始从每条路径开始并将所有距离相加
【讨论】: