Spanning Tree
Spanning Tree
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.
root r
parent of v
child of v
Cutting-down Method
Start choosing any cycle in G.
Remove one of cycle's edges.
Repeat this procedure until there are no cycle left.
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.
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.
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.
w(T ) w((v, u ))
( v ,u )T
Kruskal‘s Algorithm
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
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