Shortest path with a fixed number of edges

后端 未结 5 1296
陌清茗
陌清茗 2021-02-03 16:28

Find the shortest path through a graph in efficient time, with the additional constraint that the path must contain exactly n nodes.

We have a directed, weighte

5条回答
  •  情歌与酒
    2021-02-03 16:48

    The alternative that comes to my mind is a depth first search (as opposed to Dijkstra's breadth first search), modified as follows:

    • stop "depth"-ing if the required vertex count is exceeded

    • record the shortest found (thus far) path having the correct number of nodes.

    Run time may be abysmal, but it should come up with the correct result while using a very reasonable amount of memory.

提交回复
热议问题