Suggestions for KSPA on undirected graph

后端 未结 1 1355
我寻月下人不归
我寻月下人不归 2021-01-05 20:04

There is a custom implementation of KSPA which needs to be re-written. The current implementation uses a modified Dijkstra\'s algorithm whose pseudocode is roughly explained

相关标签:
1条回答
  • 2021-01-05 20:24

    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.
    0 讨论(0)
提交回复
热议问题