Professional Documents
Culture Documents
Initialize:
Pick any node i ∈ N
NT ← i
AT ← φ
while |NT | < n do
S = {(i, j) ∈ A : i ∈ NT , j ∈
/ NT }: Set of all arcs such that i is in NT and j is not in NT
Pick (u, v) ∈ S with lowest cost
AT ← AT ∪ {(u, v)}: Add arc (u, v) to AT
NT ← NT ∪ {u}: Add node u to NT
end while
Algorithm 1: Prim’s Algorithm
4 7
1 2 5
2 3 1 9
3 4
5
1
Initialize:
AT ← φ
AI : Sort arcs in A in increasing order
while |AT | < n − 1 do
Pick arc {(i, j) ∈ AI } in a sequential manner
if Adding (i, j) to AT does not create a cycle in AT then
AT = AT ∪ {(i, j)}
end if
end while
Algorithm 2: Kruskal’s Algorithm
4 7
1 2 5
2 3 1 9
3 4
5