CSC 2300 Data Structures - PowerPoint PPT Presentation

About This Presentation
Title:

CSC 2300 Data Structures

Description:

Given a directed graph G=(V,E) with edge capacities cvw. Examples: amount of water that flow through a pipe, or ... How to get around problem on previous ? ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 26
Provided by: stude6
Learn more at: http://www.cs.rpi.edu
Category:
Tags: csc | data | structures

less

Transcript and Presenter's Notes

Title: CSC 2300 Data Structures


1
CSC 2300Data Structures Algorithms
  • April 17, 2007
  • Chapter 9. Graph Algorithms

2
Today
  • Network Flow
  • Minimum Spanning Tree
  • Prims Algorithm

3
Network Flow
  • Given a directed graph G(V,E) with edge
    capacities cvw.
  • Examples amount of water that flow through a
    pipe, or amount of traffic on a street between
    two intersections.
  • Also given two vertices source s and sink t.
  • Goal determine the maximum amount of flow that
    can pass from s to t.

4
Example
  • A graph and its maximum flow

5
Procedure
  • Start with our graph G.
  • Construct a flow graph Gf, which gives the flow
    that has been attained at the current stage.
  • Initially, all edges in Gf have no flow.
  • Also construct a graph Gr, called the residual
    graph.
  • Each edge of Gr tells us how much more flow can
    be added.

6
Initial Stage
  • Graphs G, Gf, and Gr

7
Stage 2
  • Two units of flow are added along s, b, d, t

8
Stage 3
  • Two units of flow are added along s, a, c, t

9
Stage 4
  • One unit of flow added along s, a, d, t
  • Algorithm terminates with correct solution.

10
Greedy Algorithm
  • We have described a greedy algorithm, which does
    not always work.
  • Here is an example
  • Algorithm terminates with suboptimal solution.

11
Improve Algorithm
  • How to make the algorithm work?
  • Allow it to change its mind!
  • For every edge (v,w) with flow fvw in the flow
    graph, we will add an edge in the residual graph
    (w,v) of capacity fvw.
  • What are we doing?
  • We are allowing the algorithm to undo its
    decisions by sending flow back in the opposite
    direction.

12
Augmenting Path
  • Old
  • New

13
Improved Algorithm
  • Two units of flow are added along s, b, d, a, c,
    t
  • Algorithm terminates with correct solution.

14
Algorithm Always Works?
  • Theorem. If the edge capacities are rational
    numbers, then the improved algorithm always
    terminates with a maximal flow.
  • What are rational numbers?

15
Running Time
  • Say that the capacities are all integers and the
    maximal flow is f.
  • Each augmenting flow increases the flow value by
    at least one.
  • How many stages?
  • Augmenting path can be found by which algorithm?
  • Unweighted shortest path.
  • Total time?
  • O( f E ).

16
Bad Case
  • This is a classic bad case for augmenting
  • The maximum flow is easily seen by inspection.
  • Random augmentations could go along a path that
    includes (a,b).
  • What is the worst case for number of
    augmentations?
  • 2,000,000.

17
Remedy
  • How to get around problem on previous slide?
  • Choose the augmenting path that gives the largest
    increase in flow.
  • Which algorithm?
  • Modify the Dijkstras algorithm that solves a
    weighted shortest-path problem.

18
Minimum Spanning Tree
19
Example
20
Second Example
  • A graph and its minimum spanning tree

21
Prims Algorithm
  • Outline

22
Prims Algorithm
23
Prims Algorithm Tables
24
Another Algorithm
  • Can you name another algorithm that is very
    similar to Prims algorithm?
  • Dijkstras algorithm.
  • What is the major difference?

25
Running Time
  • Without heaps?
  • O( V2 ).
  • Optimal for dense graphs.
  • With heaps?
  • O( E logV ).
  • Good for sparse graphs.
Write a Comment
User Comments (0)
About PowerShow.com