Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Graph – Minimum Spanning

Tree – Kruskal Algorithm

P VASUKI
Definition
• A (free) tree is a connected undirected
graph with no cycles.

• A spanning tree for an undirected graph is


a free tree that contains all of its vertices
– spanning trees exists iff the graph is
connected

• For example, given n islands and a desire


to connect them with bridges, the minimal
set of bridges forms a spanning tree.
• The minimal set of bridges has size n-1
– spanning trees always have n-1 edges

• Minimizing the total cost of constructing the


bridges corresponds to finding a minimum
cost spanning tree.

• Here we begin with a weighted graph where


the cost of the edge {v,w} is the cost of
building the bridge between v and w.
– not the cost of using it
• Kruskal algorithm collects the edges
• Retrieve the edges using Minheap
(Min heap – pushes the element with
minimum cost)

• If the edge connects the edges,


which are not connected earlier add it
to the tree, if not leave it.
Kruskal’s Algorithm – Example

A
A
6
12

B 5 C C
8 B
12

12 D 7 D
3 1 1
9 F
F
E
E
A
A

B 5 C
B C

D
D 1
1 3
3 F
F
E
E
A
A
6
6

B 8 5 C
B 5 C

D D
1 1
3 3
F F
E E

You might also like