【发布时间】:2019-05-14 02:08:40
【问题描述】:
Dijkstra((V, E)):
S = {} //O(1)
for each vertex v ∈ V: //O(V)
d[v] = ∞ //O(1)
d[source] = 0 //O(1)
while S != V: //O(V)
v = non visited vertex with the smallest d[v] //O(V)
for each edge (v, u): //O(E)
if u ∈/ S and d[v] + w(v, u) < d[u]:
d[u] = d[v] + w(v, u)
S = S ∪ {v}
注意:∈/表示不在,我无法在代码中输入。
这个问题可能与某些帖子重复。
Understanding Time complexity calculation for Dijkstra Algorithm
Complexity Of Dijkstra's algorithm
Complexity in Dijkstras algorithm
我阅读了它们,甚至在 Quora 上阅读了一些帖子,但仍然无法理解。我在伪代码中放了一些 cmets 并试图解决它。我真的很困惑为什么它是 O(E log V)
【问题讨论】: