0% found this document useful (0 votes)
2 views59 pages

Spanning Tree

The document discusses Minimum Spanning Trees (MST) in undirected graphs, defining a tree and spanning tree, and explaining methods to find spanning trees such as the Cutting-down and Building-up methods. It introduces minimum spanning trees in networks with weighted edges and presents two algorithms for finding MSTs: Kruskal's and Prim's algorithms. The document emphasizes the importance of spanning trees in ensuring connectivity in graphs and minimizing weights in network applications.

Uploaded by

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

Spanning Tree

The document discusses Minimum Spanning Trees (MST) in undirected graphs, defining a tree and spanning tree, and explaining methods to find spanning trees such as the Cutting-down and Building-up methods. It introduces minimum spanning trees in networks with weighted edges and presents two algorithms for finding MSTs: Kruskal's and Prim's algorithms. The document emphasizes the importance of spanning trees in ensuring connectivity in graphs and minimizing weights in network applications.

Uploaded by

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

Minimum Spanning Tree (MST)

Trees
An undirected graph is a tree if it is connected
and does not contain a cycle.

3
For example
A leaf (or pendant vertex) is a vertex of degree 1.

A spanning subgraph of G is a subgraph with vertex


set V (G).

A spanning tree is a spanning subgraph which is a


tree.
Rooted Trees
Given a tree T, choose a root node r and orient
each edge away from r.
Application: Models hierarchical structure.

root r
parent of v

child of v

a tree the same tree, rooted at 1


(5) G is connected and each edge is a
bridge.

(6) G contains no cycles, but the addition of


any new edge creates exactly one cycles.
A simple binary tree of size 9 and height 3, with a root node whose value is 2. The
above tree is neither a sorted nor a balanced binary tree
Spanning Trees

Let G be a connected graph. A spanning tree in G is a subgraph of G that includes


all the vertices of G and is also a tree. The edges of the trees are called branches.

For example, consider the following graph G

The three spanning trees G are:


We can find a spanning tree systematically by using either of two methods.

Cutting-down Method
 Start choosing any cycle in G.
 Remove one of cycle's edges.
 Repeat this procedure until there are no cycle left.

For example, given the graph G

1. We remove the edge ac which destroy the cycle adca in the above graph and we
get
2. We remove the edge cb, which destroy the cycle adcba in the above graph and
we get

3. We remove the edge ec, which destroy the cycle decd in the above graph and
thus obtained the following spanning tree.
Building-up Method
Select edges of G one at a time in such a way that no cycles are created.
Repeat this procedure until all vertices are included.

For example, for the following graph G

1. Choose the edge ab 2. Next choose the edge de as follows:


3. After that choose the edge ec as follows:

4. Finally, we choose the edge cb and thus obtain the following spanning tree.
Theorem A graph is connected if and only if it has a spanning
tree.

Proof:
Let G be a connected graph. Delete edges from G that are not bridges until
we get a connected subgraph H in which each edge is a bridge. Then H is a
spanning tree. On the other hand, if there is a spanning tree in G, there is a
path between any pair of vertices in G; thus G is connected.
Minimum Spanning Trees

A network (directed network) is a graph (digraph) where the edges (arcs) have been
assigned non-negative real numbers. The numbers that have been assigned are called
weights.

Definition: A minimum spanning tree in a network is a spanning tree of the underlying


graph which has the smallest sum of weights amongst all spanning trees.

Example: Suppose that the vertices of a graph represent towns and the edges of the
graph are roads between these towns. Label each edge with the distance between the
towns. If, in this network, it is desired to run telephone wires along the roads so that all
the towns are connected. Where should the wires be put to minimize the amount of
wire needed to do this?
To answer the question, we need to find a minimum spanning tree in the network.

We give two greedy algorithms for finding minimum spanning trees.

Kruskal's Algorithm Prim's Algorithm


MST-Algorithms

Input: A weighted connected graph G = (V,E) with n vertices


and m edges

Output: A minimum- spanning tree T

w(T )   w((v, u ))
( v ,u )T
Kruskal‘s Algorithm

1. Each vertex is in its own cluster

2. Take the edge e with the smallest weight


- if e connects two vertices in different clusters,
then e is added to the MST and the two clusters,
which are connected by e, are merged into a single cluster
- if e connects two vertices, which are already in the same
cluster, ignore it

3. Continue until n-1 edges were selected


5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3 cycle!!
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
minimum- spanning tree

A B
2

2 D
C

3 1 2
E F
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1?
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2? 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5?
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8? 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9?
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13? 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14? 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17?
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19?
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21? 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25?
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Kruskal’s Algorithm
Run the algorithm:
Kruskal() 2 19
{ 9
14 17
T = ; 8 25
5
for each v  V
21 13 1
MakeSet(v);
sort E by increasing edge weight w
for each (u,v)  E (in sorted order)
if FindSet(u)  FindSet(v)
T = T U {{u,v}};
Union(FindSet(u), FindSet(v));
}
Prim‘s Algorithm

1. All vertices are marked as not visited

2. Any vertex v you like is chosen as starting vertex and


is marked as visited (define a cluster C)

3. The smallest- weighted edge e = (v,u), which connects


one vertex v inside the cluster C with another vertex u outside
of C, is chosen and is added to the MST.

4. The process is repeated until a spanning tree is formed


5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 6 2

2 D 3
C

3 1 2
E F
4
5
A B
4 2
6
2 D 3
C

3 1 2
E F
4
5
A B
4 2
6
2 D 3
C

3 1 2
E F
4
5
A B
4 2
6
2 D
C 3

3 1 2
E F
4
5
A B
4 2
6
2 D
C 3

3 1 2
E F
4
minimum- spanning tree

A B
2

2 D
C

3 1 2
E F

You might also like