Kruskals MST and Efficient Implementation - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Kruskals MST and Efficient Implementation

Description:

We will therefore identify the name of the component of a node with the root. For efficiency, we will maintain shallow trees, so that the time to reach the ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 13
Provided by: CNS260
Category:

less

Transcript and Presenter's Notes

Title: Kruskals MST and Efficient Implementation


1
5th Set of Lecture Notes
Thu, Jan 22 04
Kruskals MST and Efficient Implementation
Reading CLRS Chapter 23 and these Lecture Notes
2
Undirected graph G (V,E). Adjacency List
Representation is O ( VE ).
V1 ? v3 , v5
v1
v2
v2 ?
v5
v3
V3 ? v1 , v5
V4 ?v5 , v6
V5 ? v1 , v3 , v4
v6
v4
V6 ? v4
3
Spanning Trees
Definition A subset of edges such that every
pair of vertices is connected by a unique
path. Facts (a) A spanning tree has no
cycles. (b) A spanning tree on n
vertices has n-1 edges. (c) If an
edge is added to a spanning tree then we create a
unique cycle. (d) If we remove any
edge from the unique cycle of (c) then we get a
spanning tree.
4
When there are weights on the edges then the cost
of a spanning tree
is the sum of the costs of the weights of its
edges. We want a Minimum Cost Spanning Tree
(MST).
20
v1
v2
15
23
1
4
9
v3
36
v7
v6
16
3
25
28
v4
v5
17
Let us assume that all edges have distinct costs.
5
Where shall we start?
Fact The mincost edge is in every mincost
spanning tree.
Proof By contradiction. Let e be the mincost
edge and let T be a minimum cost spanning tree
that does not contain e. Add e to T , thus
creating a unique cycle. Since e is the mincost
edge, every other edge e of this cycle is more
expensive than e. So we can remove any edge e
from the cycle and get a spanning tree T T e
e cheaper than T . But this contradicts the
assumption that T is a mincost spanning tree.
6
Lets build a greedy algorithm by repeatedly
adding mincost edges.
7
Is the Previous Algorithm Correct?
Fact For every cut S (where S is a subset of
the vertives), the mincost edge (u,v) across the
cut (where u is in S and v is in V-S) is in
every mincost spanning tree.
Proof By contradiction. Let e be the mincost
edge across the cut S , and let T be a minimum
cost spanning tree that does not contain e. Add
e to T , thus creating a unique cycle. Each
cycle crosses each cut an even number of
times. Since the created cycle crosses the cut at
least once, by e , it must cross it at least one
more time to get to a non-negative even number.
Let e be another edge of the cycle crossing the
cut S .Since e is the mincost edge, every other
edge e of this cycle is more expensive than e.
So we can remove any edge e from the cycle and
get a spanning treeT T e e cheaper than
T . But this contradicts the assumption that T
is a mincost spanning tree.
T
e
e
8
Efficient Implementation We can implement Q
with a heap. But how shall we maintain the
components of the tree T ? In particular We
want to efficiently check if two nodes belong to
the same component. We want to efficiently take
the union of two components.
9
Keep the nodes of a component in a tree. The name
of the component will be the root of the tree. We
will therefore identify the name of the component
of a node with the root. For efficiency, we will
maintain shallow trees, so that the time to reach
the root will be small. In particular, we will
make sure that a tree of depth h contains at
least 2h nodes.
10
Here is the data structure Every node has a
parent. If the parent is NIL then the node is a
root. The name of the component of a node is the
root of the tree that the node belongs to.
11
Every node has a rank. The rank of a node is the
depth of the tree hanging from the node. The
number of nodes of the tree hanging off of a node
x is at least as large as 2rank(x) .
Notice When we are increasing the rank
(height) by 1, the union component is of size at
least two times the size of the smaller
part. Proof is inductive on height.
12
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com