next up previous
Next: Up: Previous:

Pseudocode

MST-Prim(G, w, r)  
1 foreach v in V ; O(V), BuildHeap
2 $\;\;\;\;\;$key(v) = $\infty$ ; Fibonacci Heap O(E + V lg V)
3 $\;\;\;\;\;$(inQ(v) = true)  
4 $\;\;\;\;\;$Insert(Q, v)  
5 key(r) = 0  
6 parent(r) = NIL  
7 while Q $\neq$ NIL ; O(V)
8 $\;\;\;\;\;$u = Extract-Min(Q) ; O(lg V)
9 $\;\;\;\;\;$(inQ(u) = false) ; Fibonacci Heap O(lg V)
10 $\;\;\;\;\;$foreach v in Adj(u) ; O(E) total
11 $\;\;\;\;\;$ $\;\;\;\;\;$if inQ(v) and w(u,v) < key(v) ; 2 |E|
12 $\;\;\;\;\;$ $\;\;\;\;\;$then parent(v) = u ; O(lg V), DecreaseKey
13 $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$key(v) = w(u,v) ; O(V lg V + E lg V)



O(V lg V + E lg V) = O(E lg V)
Fibonacci Heap: O(E + V lg V)


next up previous
Next: Up: Previous: