Introduction to Algorithms - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Introduction to Algorithms

Description:

Introduction to Algorithms Minimum Spanning Trees My T. Thai _at_ UF Problem Find a low cost network connecting a set of locations Any pair of locations are connected ... – PowerPoint PPT presentation

Number of Views:148
Avg rating:3.0/5.0
Slides: 21
Provided by: MYTRATHAI
Learn more at: https://www.cise.ufl.edu
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Algorithms


1
Introduction to Algorithms
  • Minimum Spanning Trees
  • My T. Thai _at_ UF

2
Problem
  • Find a low cost network connecting a set of
    locations
  • Any pair of locations are connected
  • There is no cycle
  • Some applications
  • Communication networks
  • Circuit design

3
Minimum Spanning Tree (MST) Problem
  • Input Undirected, connected graph G(V, E), each
    edge (u, v) ? E has weight w(u, v)
  • Output acyclic subset T ? E that connects all
    of the vertices with minimum total weight
  • w(T) ?(u,v)?T w(u,v)

Bold edges form a Minimum Spanning Tree
4
Growing a minimum spanning tree
  • Suppose A is a subset of some MST
  • Iteratively add safe edge (u,v) s.t. A ? (u,v)
    is still a subset of some MST
  • Generic algorithm

Key problem How to find safe edges?
Note MST has V-1 edges
5
Some definitions
  • A cut (S, V - S) is a partition of vertices into
    disjoint sets S and V - S
  • An edge crosses the cut (S, V - S) if it has one
    end point in S, one end point in V - S
  • A cut respects a set A of edges if and only if no
    edge in A crosses the cut, e.g. A is the set of
    bold edges

6
Some definitions
  • An edge is a light edge crossing a cut if and
    only if its weight is minimum over all edges
    crossing the cut, e.g. edge (c, d)
  • Observation Any MST has at least one edge
    connect S and V S gt one cross edge is safe for
    A

7
Find a safe edge
  • Proof Let T be a MST that includes A
  • Case 1 (u, v) ? T gt done.
  • Case 2 (u, v) not in T
  • Exist edge (x, y) ?T cross the cut, (x, y) A
  • Removing (x, y) breaks T into two components.
  • Adding (u, v) reconnects 2 components
  • T T - (x, y) ? (u, v) is a spanning tree
  • w(T) w(T) - w(x, y) w(u, v) ? w(T) gt T is
    a MST gt done

8
Corollary
  • In GENERIC-MST
  • A is a forest containing connected components.
    Initially, each component is a single vertex.
  • Any safe edge merges two of these components into
    one. Each component is a tree.

9
Kruskals Algorithm
  • Starts with each vertex in its own component
  • Repeatedly merges two components into one by
    choosing a light edge that connects them (i.e., a
    light edge crossing the cut between them)
  • Scans the set of edges in monotonically
    increasing order by weight.
  • Uses a disjoint-set data structure to determine
    whether an edge connects vertices in different
    components

10
Disjoint-set data structure
  • Maintain collection S S1, . . . , Sk of
    disjoint dynamic (changing over time) sets
  • Each set is identified by a representative, which
    is some member of the set
  • Operations
  • MAKE-SET(x) make a new set Si x, and add Si
    to S
  • UNION(x, y) if x ? Sx , y ? Sy, then S ? S - Sx
    - Sy ? Sx ? Sy
  • Representative of new set is any member of Sx ?
    Sy, often the representative of one of Sx and Sy.
  • Destroys Sx and Sy (since sets must be disjoint).
  • FIND-SET(x) return representative of set
    containing x
  • In Kruskals Algorithm, each set is a connected
    component

11
Pseudo code
  • Running time O(E lg V) ( is E is
    sorted)
  • First for loop V MAKE-SETs
  • Sort E O(E lg E) - O(E lg V)
  • Second for loop (o(E log V)
    (chapter 21)

12
Example
13
(No Transcript)
14
Prims Algorithm
  • Builds one tree, so A always a tree
  • Starts from an arbitrary root r
  • At each step, find a light edge crossing cut (VA,
    V - VA), where VA vertices that A is incident
    on. Add this edge to A.

15
Prims Algorithm
  • Uses a priority queue Q to find a light edge
    quickly
  • Each object in Q is a vertex in V - VA
  • Key of v is minimum weight of any edge (u, v),
    where u ? VA
  • Then the vertex returned by Extract-Min is v such
    that there exists u ? VA and (u, v) is light edge
    crossing (VA, V VA)
  • Key of v is ? if v is not adjacent to any vertex
    in VA

16
  • Running time O(E lgV)
  • Using binary heaps to implement Q
  • Initialization O(V)
  • Building initial queue O(V)
  • V Extract-Mins O(V lgV)
  • E Decrease-Keys O(E lgV)
  • Note Using Fibonacci heaps can save time of
    Decrease-Key operations to constant (chapter 19)
    gt running time O(E V lg V)

17
Example
18
(No Transcript)
19
Summary
  • MST T of connected undirect graph G (V, E)
  • Is a subgraph of G
  • Connected
  • Has V vertices, V -1 edges
  • There is exactly 1 path between a pair of
    vertices
  • Deleting any edge of T disconnects T
  • Kruskals algorithm connects disjoint sets of
    connects vertices until achieve a MST
  • Run nearly linear time if E is sorted

20
Summary
  • Prims algorithm starts from one vertex and
    iteratively add vertex one by one until achieve a
    MST
  • Faster than Kruskals algorithm if the graph is
    dense O(E V lg V) vs O(E lg V)
Write a Comment
User Comments (0)
About PowerShow.com