323 Lecture Notes 8 Part 2
323 Lecture Notes 8 Part 2
Greedy Technique
𝜽(𝒍𝒈𝒏)
𝜽(𝒍𝒈𝒏)
Minimum Spanning Tree
Given a weighted graph find an acyclic subset that connects all
of the vertices and whose total weight is minimized.
A spanning tree with total cost = 15 A spanning tree with total cost = 13
1 3 1 1 3
7 5 2 7 5 2 7
2 2
Given graph𝐺=(𝑉 , 𝐸) 1 3
2
Minimum Spanning Tree with total cost = 8
Minimum Spanning Tree
Growing a Minimum Spanning Tree (MST):
Grow the MST one edge at a time, iteratively without violating
the following loop invariant
Before each iteration, is a subset of some MST
Definition: At any time of iteration current MST is a set and if
is also a subset of a MST then is said to be a safe edge.
Minimum Spanning Tree
Below algorithm uses Greedy strategy
Question: How to find safe edges ?
Minimum Spanning Tree
Example:
Minimum Spanning Tree
Definition: A cut of an undirected graph is a partition of .
Definition: An edge crosses the cut if one of its endpoints is
in and the other is in .
Definition: An edge is a light edge crossing a cut if its weight
is the minimum of any edge crossing the cut.
More than one light edge is possible.
Minimum Spanning Tree
Definition: A cut respects a set of edges if no edge in
crosses the cut.
Theorem:
Let be a connected undirected graph with a real-valued weight
function defined on .
Let be a subset of that is included in some Minimum Spanning Tree
for .
Let be any cut of that respects
Let be a light edge crossing
𝑶(𝒍𝒈𝑽 )
𝑶(𝒍𝒈𝑽 )
Minimum Spanning Tree: Kruskal’s
Algorithm
Since graph is connected
If then .
So, time complexity is
Minimum Spanning Tree: Prim’s
Algorithm
A Greedy algorithm
𝐎 (𝑽 )
Time complexity:
𝜽( 𝑽 )
𝑶(𝑽𝒍𝒈𝑽 )
𝑶(𝒍𝒈𝑽 )
𝜽( 𝑬 )
𝑶(𝑬𝒍𝒈𝑽 )
𝑶(𝒍𝒈𝑽 )
Dominant
Term
Decrease Key