Lecture 7 Greedy algorithms: minimum spanning tree - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Lecture 7 Greedy algorithms: minimum spanning tree

Description:

Output: finding the spanning tree such that the sum of weights is not bigger ... Spanning tree: subgraph with ... e) - obtain a spanning tree with the smaller ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 14
Provided by: DarekKo5
Category:

less

Transcript and Presenter's Notes

Title: Lecture 7 Greedy algorithms: minimum spanning tree


1
Lecture 7 Greedy algorithmsminimum spanning
tree
  • COMP 523 Advanced Algorithmic Techniques
  • Lecturer Dariusz Kowalski

2
Overview
  • Previous lectures
  • Greedy algorithms
  • Interval scheduling
  • This lecture
  • Minimum spanning tree - many greedy approaches

3
Greedy algorithms paradigm
  • Algorithm is greedy if
  • it builds up a solution in small steps
  • it chooses a decision at each step myopically to
    optimize some underlying criterion
  • Analyzing optimal greedy algorithms by showing
    that
  • in every step it is not worse than any other
    algorithm, or
  • every algorithm can be gradually transformed to
    the greedy one without hurting its quality

4
Minimum spanning tree
  • Input weighted graph G (V,E)
  • every edge in E has its positive weight
  • Output finding the spanning tree such that the
    sum of weights is not bigger than the sum of
    weights of any other spanning tree
  • Spanning tree subgraph with
  • no cycle, and
  • connected (every two nodes in V are connected by
    a path)

2
2
2
1
1
1
1
1
1
2
2
2
3
3
3
5
Properties of minimum spanning trees MST
  • Spanning trees
  • n nodes
  • n - 1 edges
  • at least 2 leaves (leaf - a node with only one
    neighbor)
  • MST cycle property
  • After adding an edge we obtain exactly one cycle
    and all the edges from MST in this cycle have no
    bigger weight than the weight of the added edge

2
2
1
1
1
1
2
2
3
3
cycle
6
Crucial observation about MST
  • Consider sets of nodes A and V - A
  • Let F be the set of edges between A and V - A
  • Let a be the smallest weight of an edge from F
  • Theorem
  • Every MST must contain at least one edge of
    weight a
  • from set F

A
A
2
2
1
1
1
1
2
2
3
3
7
Proof of the observation
  • Let e be the edge in F with the smallest weight -
    for simplicity
  • assume that there is unique such edge. Suppose to
    the contrary that
  • e is not in some MST. Choose one such MST.
  • Add e to MST - obtain the cycle, where e is
    (among) smallest weights.
  • Since two ends of e are in different sets A and V
    - A,
  • there is another edge f in the cycle and in F.
    Remove f from the tree
  • (with added edge e) - obtain a spanning tree with
    the smaller weight
  • (since f has bigger weight than e). This is a
    contradiction with MST.

A
A
2
2
1
1
1
1
2
2
3
3
8
Greedy algorithm finding MST
  • Kruskals algorithm
  • Sort all edges according to the weights
  • Choose n - 1 edges one after another as follows
  • If a new added edge does not create a cycle with
    previously selected then we keep it in (partial)
    MST, otherwise we remove it
  • Remark we always have a partial forest

2
2
2
1
1
1
1
1
1
2
2
2
3
3
3
9
Greedy algorithm finding MST
  • Prims algorithm
  • Select a node as a root arbitrarily
  • Choose n - 1 edges one after another as follows
  • Look on all edges incident to the currently build
    (partial) tree and which do not create a cycle in
    it, and select one which has the smallest weight
  • Remark we always have a connected partial tree

root
2
2
2
1
1
1
1
1
1
2
2
2
3
3
3
10
Why the algorithms work?
  • Follows from the crucial observation
  • Kruskals algorithm
  • Suppose we add edge v,w. This edge has the
    smallest weight among edges between the set of
    nodes already connected with v (by a path in
    selected subgraph) and other nodes.
  • Prims algorithm
  • Always chooses an edge with the smallest weight
    among edges between the set of already connected
    nodes and free nodes.

11
Time complexity
  • There are implementations using
  • Union-find data structure (Kruskals algorithm)
  • Priority queue (Prims algorithm)
  • achieving time complexity
  • O(m log n)
  • where n is the number of nodes and m is the
  • number of edges

12
Conclusions
  • Greedy algorithms for finding minimum
  • spanning tree in a graph, both in time
  • O(m log n)
  • Kruskals algorithm
  • Prims algorithm
  • Remains to design the efficient data structures!

13
Exercises
  • Solved Exercise 3 from textbook - Chapter 4
    Greedy Algorithms
Write a Comment
User Comments (0)
About PowerShow.com