0
我希望對以下問題有所幫助/指導,我正在努力解決這個問題。 如果您對重新提出問題有任何建議,請留下評論,我會繼續並改變它。從任意節點到另一個節點找到最短路徑(長度和實際路徑)的遞歸和動態規劃算法
取加權有向無環圖。 (a)找到從節點x到節點t的最短路徑的遞歸算法(算法應該嘗試所有出邊並決定繼續進行)。
I was thinking something along the lines of breadth first search?
Maybe, another way, a recursive form of dijkstras? However, I'm having
difficulty thinking of a recursive way to do this.
(b)作出遞歸算法的迭代動態規劃版本,並註明你是怎麼找到的實際路徑(而不是路徑的只是長度)。
The difference here would obviously be that it is iterative. I'm also
guessing we would have to keep track of the length of the path/the
path itself (the nodes) in an array, and refer to it as we iterate.
謝謝你的回答!你能否深入瞭解一下它的工作原理? –
如果存在從A到C的路徑,以便該路徑上有兩條邊一起加權4,並且從A到C的路有一條路徑,使得它的權重爲8.該算法如何決定採用權重的2個邊4而不是重量8的1邊緣? –
@RonaldDonald這是'min {}'的用途。它以最小的成本選擇路徑。 – amit