Dijkstra's Algo
Last updated
Last updated
即使中間多了一個 A 2.5, 0.4 在下一輪仍然可以 update 成2.9
但如果是更差的結果, seattle: 3 不需要更新
create an effort matrix stores effort record
create PriorityQueue accept int[] : new_dist(effort), row, col, order by effort (minHeap)
while PriorityQueue is not empty
poll node data from PriorityQueue (the smallest dist and row, col index)
if dist > effort[row][col] ⇒ skip this round
if row & col == last cell ⇒ return result
search this node's all neighbors, find new dist ⇒ new smaller effort
if find new dist < effort[new_row][new_col] ⇒ update effort[new_row][new_col] = new dist, and offer new smaller dist into PriorityQueue