1 / 25

CSC 2300 Data Structures & Algorithms

CSC 2300 Data Structures & Algorithms. April 17, 2007 Chapter 9. Graph Algorithms. Today. Network Flow Minimum Spanning Tree Prim’s Algorithm. Network Flow. Given a directed graph G=(V,E) with edge capacities c vw .

pabla
Download Presentation

CSC 2300 Data Structures & Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Today • Network Flow • Minimum Spanning Tree • Prim’s 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 Dijkstra’s 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. Prim’s Algorithm • Outline:

  22. Prim’s Algorithm

  23. Prim’s Algorithm – Tables

  24. Another Algorithm • Can you name another algorithm that is very similar to Prim’s algorithm? • Dijkstra’s algorithm. • What is the major difference?

  25. Running Time • Without heaps? • O( |V|2 ). • Optimal for dense graphs. • With heaps? • O( |E| log|V| ). • Good for sparse graphs.

More Related