Suggestions for KSPA on undirected graph

依然范特西╮ 提交于 2019-11-30 22:15:03

Time complexity: O(K*(E*log(K)+V*log(V)))

Memory complexity of O(K*V) (+O(E) for storing the input).

We perform a modified Djikstra as follows:

  • For each node, instead of keeping the best currently-known cost of route from start-node. We keep the best K routes from start node
  • When updating a nodes' neighbours, we don't check if it improves the best currently known path (like Djikstra does), we check if it improves the worst of the K' best currently known path.
  • After we already processed the first of a nodes' K best routes, we don't need to find K best routes, but only have K-1 remaining, and after another one K-2. That's what I called K'.
  • For each node we will keep two priority queues for the K' best currently known path-lengths.
    • In one priority queue the shortest path is on top. We use this priority queue to determine which of the K' is best and will be used in the regular Djikstra's priority queues as the node's representative.
    • In the other priority queue the longest path is on top. We use this one to compare candidate paths to the worst of the K' paths.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!