0% found this document useful (0 votes)
14 views3 pages

Minimum Spanning Trees - Time Complexity

Uploaded by

nay33n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Minimum Spanning Trees - Time Complexity

Uploaded by

nay33n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Minimum Spanning Trees –

Time Complexity
Kruskal's algorithm

G = (V, E) is a connected, undirected, weighted graph. ω : E → R.

KRUSKAL(V, E, ω)
A=∅
for each vertex υ ∈ V // O(|V|)
MAKE-SET(υ)

Sort E into non-decreasing order by weight ω // O(|E| log |E|)

for each (u, υ) in the sorted list : // O(|E| log*|V|) = O(|E|)


u' = FIND(u)
v' = FIND(v) more than |E| FIND and UNION operation in |V| items
if u' ≠ υ' : // check cycle
A = A ∪ {(u, υ)}
UNION(u, υ) // connect two trees by adding (u ,v)

return A

2
Prim’s algorithm

G = (V, E) is a connected, undirected, weighted graph. ω : E → R.

PRIM(V, E, ω)
Pick randomly a node r in V
for each u ∈ V // O(|V|)
π[u] = NIL; key[u] = ∞

Q = BUILD_MIN_HEAP(V-{r}) // O(|V|)
A= ∅
u = r // a start node to expand

repeat :
for each υ ∈ Adj[u] :
if υ ∈ Q and ω(u, υ) < key[υ] : // update the key value of cross edges
π[υ] = u
DECREASE-KEY(Q, υ, ω(u, υ)) // O(|E| |log |V|)
u' ← EXTRACT-MIN(Q) // O(|V| |log |V|)
A = A ∪ {(π[u'], u')}
until Q is empty
O((|E| + |V|) |log |V|) if Q is a binary heap
return A O(|E| + |V| |log |V|) if Q is a Fibonacci heap 3

You might also like