Kruskal’s MST Maximum Flow

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
Advertisements

Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8.
Minimum Spanning Trees
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
ADA: 10. MSTs1 Objective o look at two algorithms for finding mimimum spanning trees (MSTs) over graphs Prim's algorithm, Kruskal's algorithm Algorithm.
Charles Lin. Graph Representation Graph Representation DFS DFS BFS BFS Dijkstra Dijkstra A* Search A* Search Bellman-Ford Bellman-Ford Floyd-Warshall.
MST and Max Flow CS3233. Overview Two Graph Problems Minimum Spanning Tree Maximum Flow/Minimum Cut Problem One Data Structure Disjoint Sets.
Minimum spanning trees (MST) Def: A spanning tree of a graph G is an acyclic subset of edges of G connecting all vertices in G. A sub-forest of G is an.
Fundamental Data Structures and Algorithms Peter Lee April 24, 2003 Union-Find.
Minimum- Spanning Trees
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
A directed graph G consists of a set V of vertices and a set E of arcs where each arc in E is associated with an ordered pair of vertices from V. V={0,
Graph Search Applications, Minimum Spanning Tree
Lecture ? The Algorithms of Kruskal and Prim
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Max-flow, Min-cut Network flow.
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Greedy function greedy { S <- S0 //Initialization
Lecture 22 Minimum Spanning Tree
Network flow problem [Adapted from M.Chandy].
Maximum Flow 9/13/2018 6:12 PM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.
CSCI 3160 Design and Analysis of Algorithms Tutorial 8
Compsci 201, Union-Find Algorithms
Network Flow.
Minimum Spanning Trees and Shortest Paths
CISC 235: Topic 10 Graph Algorithms.
Max Flow min Cut.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
CSE 5311-Class Project Bipartite Matching using Network Flow
Graph Algorithm.
Minimum-Cost Spanning Tree
Max-flow, Min-cut Network flow.
Minimum Spanning Tree.
Lecture 16 Maximum Matching
Network Flow 2016/04/12.
Instructor: Shengyu Zhang
Edmonds-Karp Algorithm
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
CSE Algorithms Max Flow Problems 11/21/02 CSE Max Flow.
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
MST - Prim’s Algorithm Greedy algorithm that “grows” an MST by repeatedly finding the lowest cost edge that will connect a new vertex to MST For every.
Correctness of Edmonds-Karp
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Union-find algorithms
CSE 373: Data Structures and Algorithms
Network Flow CSE 373 Data Structures.
EE5900 Advanced Embedded System For Smart Infrastructure
離散數學 DISCRETE and COMBINATORIAL MATHEMATICS
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Text Book: Introduction to algorithms By C L R S
Network Flow.
Lecture 21 Network Flow, Part 1
MAXIMUM flow by Eric Wengert.
Richard Anderson Lecture 22 Network Flow
7. Edmonds-Karp Algorithm
Maximum Flow Neil Tang 4/8/2008
7. Edmonds-karp Demo.
Kruskal’s Algorithm AQR.
CSE 373: Data Structures and Algorithms
Network Flow.
Maximum Bipartite Matching
Richard Anderson Lecture 22 Network Flow
Advanced Graph Homer Lee 2013/10/31.
Minimum-Cost Spanning Tree
Presentation transcript:

Kruskal’s MST Maximum Flow

Kruskal’s MST Kruskal’s MST: Insert all edges into a PQ Grab the min edge from the PQ that does not create a cycle in the MST (Union-Find) Remove it from the PQ and add it to the MST

Kruskal’s Example PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) 6 5 1 1 3 5 5 3 2 2 6 4 4 5 6

Union-Find UF eciently determines connectedness of two points. When adding edges one at a time, you can determine that if the endpoints of an edge to be added are already connected in the graph, Then adding this new edge would cause the endpoints to be biconnected, creating a cycle.

Union-Find Init Check public UF(int N) { } count = N; id = new int[N]; for (int i=0; i<N; ++i) id[i] = i; } Check public connected(int p, int q) { return find(p) == find(q);

Union-Find Find Union public int find(int p) { } while (p != id[p]) p = id[p]; } Union public void union(int p, int q) { int i = find(p); int j = find(q); if (i == j) return; id[i] = j; --count;

Kruskal’s Example using Union-Find PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) ID: 0: 0 1: 1 2: 2 3: 3 4: 4 5: 5 6 5 1 1 3 5 5 3 2 2 6 4 1 2 3 4 5 4 5 6

Kruskal’s Example using Union-Find PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) ID: 0: 0 1: 1 2: 0 3: 3 4: 4 5: 5 6 5 1 1 3 5 5 3 2 2 6 4 1 3 4 5 4 5 6 2

Kruskal’s Example using Union-Find PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) ID: 0: 0 1: 1 2: 0 3: 3 4: 4 5: 3 6 5 1 1 3 5 5 3 2 2 6 4 1 3 4 4 5 6 2 5

Kruskal’s Example using Union-Find PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) ID: 0: 0 1: 1 2: 0 3: 3 4: 1 5: 3 6 5 1 1 3 5 5 3 2 2 6 4 1 3 4 5 6 2 4 5

Kruskal’s Example using Union-Find PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) ID: 0: 0 1: 1 2: 0 3: 0 4: 1 5: 3 6 5 1 1 3 5 5 3 2 2 1 6 4 3 4 5 2 4 6 5

Kruskal’s Example using Union-Find PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) ID: 0: 0 1: 1 2: 0 3: 0 4: 1 5: 3 6 5 1 1 3 5 5 3 2 2 1 6 4 3 4 5 2 4 6 5

Kruskal’s Example using Union-Find PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) ID: 0: 0 1: 1 2: 0 3: 0 4: 1 5: 3 6 5 1 1 3 5 5 3 2 2 1 6 4 3 4 5 2 4 6 5

Kruskal’s Example using Union-Find PQ: 1: (0, 2) 2: (3, 5) 3: (1, 4) 4: (2, 5) 5: (2, 3) 5: (0, 3) 5: (1, 2) 6: (0, 1) 6: (2, 4) 6: (4, 5) ID: 0: 0 1: 0 2: 0 3: 0 4: 1 5: 3 6 5 1 1 3 5 5 3 2 2 6 4 2 3 1 4 5 6 5 4

Union-Find Worst case?

Max-flow Ford-Fulkerson Edmonds-Karp Using DFS to find the augmenting path Edmonds-Karp Using BFS to find the augmenting path Augmenting path with smallest number of edges

Edmonds Karp’s Max-flow Example 0|2 A D 0|15 0|5 0|10 0|7 s C 0|9 t 0|10 0|3 0|10 0|6 0|5 B E

Edmonds Karp’s Max-flow Example 2|2 2 s A t: min(5, 2)=2 A D 0|15 2|5 0|10 2 0|7 s C 0|9 t 0|10 0|3 0|10 0|6 0|5 B E

Edmonds Karp’s Max-flow Example 2|2 2 s A t: min(5,2)=2 s B E t: min(10,5,6)=5 A D 0|15 2|5 0|10 2 0|7 s C 0|9 t 0|10 5 0|3 5|6 5|10 5 5|5 B E 5

Edmonds Karp’s Max-flow Example 2|2 2 s A t: min(5,2)=2 s B E t: min(10,5,6)=5 s C D t: min(7,10,15)=7 A D 7|15 2|5 7|10 2 7 7 7|7 s C 0|9 t 7 0|10 5 0|3 5|6 5|10 5 5|5 B E 5

Edmonds Karp’s Max-flow Example 2|2 2 s A t: min(5,2)=2 s B E t: min(10,5,6)=5 s C D t: min(7,10,15)=7 S B C D t: min(5, 3, 3, 8)=3 A D 10|15 2|5 10|10 2 10 10 7|7 s C 0|9 t 7 0|10 8 3|3 5|6 8|10 3 5 5|5 B E 5

Edmonds Karp’s Max-flow Example 2|2 2 s A t: min(5,2)=2 s B E t: min(10,5,6)=5 s C D t: min(7,10,15)=7 S B C D t: min(5, 3, 3, 8)=3 A D 10|15 2|5 10|10 2 10 10 7|7 s C 0|9 t 7 0|10 8 3|3 5|6 8|10 5 5|5 B E 5

Edmonds Karp’s Max-flow Example 2|2 2 s A t: min(5,2)=2 s B E t: min(10,5,6)=5 s C D t: min(7,10,15)=7 S B C D t: min(5, 3, 3, 8)=3 Max-Flow=17 A D 10|15 2|5 10|10 2 10 10 7|7 s C 0|9 t 7 0|10 8 3|3 5|6 8|10 5 5|5 B E 5