MST and Max Flow CS3233. Overview Two Graph Problems Minimum Spanning Tree Maximum Flow/Minimum Cut Problem One Data Structure Disjoint Sets.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
Greed is good. (Some of the time)
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
1 Minimum Spanning Tree Prim-Jarnik algorithm Kruskal algorithm.
Minimum Spanning Tree CSE 331 Section 2 James Daly.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
1 Spanning Trees Lecture 20 CS2110 – Spring
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Minimum Spanning Tree Algorithms
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Spanning Trees.
1 7-MST Minimal Spanning Trees Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
CSE 326: Data Structures Spanning Trees Ben Lerner Summer 2007.
Minimum Cost Flow Lecture 5: Jan 25. Problems Recap Bipartite matchings General matchings Maximum flows Stable matchings Shortest paths Minimum spanning.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
Minimum Spanning Tree in Graph - Week Problem: Laying Telephone Wire Central office.
Minimum Spanning Tree Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
The Disjoint Set Class Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss Chapter 24 © 2002 Addison Wesley.
Nattee Niparnan. Greedy If solving problem is a series of steps Simply pick the one that “maximize” the immediate outcome Instead of looking for the long.
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
Nattee Niparnan. Greedy If solving problem is a series of steps Simply pick the one that “maximize” the immediate outcome Instead of looking for the long.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
SPANNING TREES Lecture 21 CS2110 – Fall Nate Foster is out of town. NO 3-4pm office hours today!
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
1 CPSC 320: Intermediate Algorithm Design and Analysis July 14, 2014.
WEEK 12 Graphs IV Minimum Spanning Tree Algorithms.
MST Lemma Let G = (V, E) be a connected, undirected graph with real-value weights on the edges. Let A be a viable subset of E (i.e. a subset of some MST),
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Minimum Spanning Trees and Shortest Paths
Lecture 12 Algorithm Analysis
CISC 235: Topic 10 Graph Algorithms.
Max Flow min Cut.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Topological Sort (topological order)
Bipartite Matching and Other Graph Algorithms
Graph Algorithm.
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Tree.
CS200: Algorithm Analysis
Spanning Trees.
Minimum-Cost Spanning Tree
Chapter 23 Minimum Spanning Tree
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Minimum Spanning Tree.
Algorithms (2IL15) – Lecture 7
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
CSE 373: Data Structures and Algorithms
Minimum-Cost Spanning Tree
Presentation transcript:

MST and Max Flow CS3233

Overview Two Graph Problems Minimum Spanning Tree Maximum Flow/Minimum Cut Problem One Data Structure Disjoint Sets

Minimum Spanning Tree Prim’s and Kruskal’s Algorithm

Spanning Tree

Minimum Spanning Tree Given a graph G, find a spanning tree where total cost is minimum.

Prim’s Algorithm

Prim’s Greedy Algorithm color all vertices yellow color the root red while there are yellow vertices pick an edge (u,v) such that u is red, v is yellow & cost(u,v) is min color v red

Why Greedy Works?

Prim’s Algorithm foreach vertex v v.key =  root.key = 0 pq = new PriorityQueue(V) while pq is not empty v = pq.deleteMin() foreach u in adj(v) if v is in pq and cost(v,u) < u.key pq.decreaseKey(u, cost(v,u))

Complexity: O((V+E)log V) foreach vertex v v.key =  root.key = 0 pq = new PriorityQueue(V) while pq is not empty v = pq.deleteMin() foreach u in adj(v) if v is in pq and cost(v,u) < u.key pq.decreaseKey(u, cost(v,u))

Kruskal’s Algorithm

while there are unprocessed edges left pick an edge e with minimum cost if adding e to MST does not form a cycle add e to MST else throw e away

Data Structures How to pick edge with minimum cost? Use a Priority Queue How to check if adding an edge can form a cycle? Use a Disjoint Set

Disjoint Set Data Structure Union/Find

Overview

Operation Union

Operation Find A B C

Application: Kruskal’s Initialize: Every vertex is one partition while there are unprocessed edges left pick edge e = (u,v) with minimum cost // if adding e to MST does not form a cycle if find(u) != find(v) add e to MST union(u, v) else throw e away

Application: Maze Generation

Algorithm Starts with walls everywhere Randomly pick two adjacent cells Knock down the wall if they are not already connected Repeat until every cell is connected

GenerateMaze(m,n) toKnock = mn-1 while toKnock != 0 pick two adjacent cells u and v if find(u) != find(v) knock down wall between u and v union(u,v) toKnock = toKnock - 1

How to implement? typedef struct item { struct item *parent; int data; } item; A BC D

Union(A, B) A B C D

Union(A, C) A B C D

Union(D, B) A B C D

Union(A, B) // find root of A // set parent of root of A to B curr = A while (curr.parent != NULL) curr = curr.parent curr.parent = B

Find(A) // return root of A curr = A while curr.parent != NULL curr = curr.parent return curr

How to make find faster? Reduce the length of path to root! union-by-rank path compression

Union by Rank (A, B) rootA = root of A rootB = root of B if tree of rootA is shorter rootA.parent = rootB else rootB.parent = rootA

find(A) with Path Compression if A.parent != NULL A.parent = find(A.parent) return A.parent else return A

Path Compression BeforeAfter

Review Minimum Spanning Tree Prim’s and Kruskal’s Algorithm Union-Find Data Structure

Variations Does Prim and Kruskal works with negative weights? How about Maximum Spanning Tree?

Max Flow/Min Cut

Problem

Definitions 7 Capacity Sink Source

A Flow

A Cut

Capacity/Flow Across A Cut

Problem Find a cut with minimum capacity Find maximum flow from source to sink

More Definition: Residual Graph

Augmenting Path A path from source to sink in the residual graph of a given flow

Idea If there is an augmenting path in the residual graph, we can push more flow

Ford-Fulkerson Method initialize total flow to 0 residual graph G’= G while augmenting path exist in G’ pick a augmenting path P in G’ m = bottleneck capacity of P add m to total flow push flow of m along P update G’

Example

Answer: Max Flow =

Answer: Minimum Cut =

Find Augmenting Path? initialize total flow to 0 residual graph G’= G while augmenting path exist in G’ pick a augmenting path P in G’ m = bottleneck capacity of P add m to total flow push flow of m along P update G’

Picking Augmenting Path Edmonds-Karp’s Heuristics I.Find a path with maximum bottleneck capacity II.Find a path with minimum length

Variations How about Maximum Cut?

Applications for MaxFlow/MinCut

Application: Bipartite Matching Marriage Problem BTW, how to determine if a graph is bipartite?

A Matching

Maximum Matching

Maximum Flow Problem

Maximum Flow/Matching

Minimum Vertex Cover Bipartite Graph

A Vertex Cover (W=15)

Maximum Flow

Finite Cut = Vertex Cover

Problems..

Problem 1: Optimal Protein Sequence Given a 2D geometric structure of a protein, with n residuals

Optimal Protein Sequence Each residual can be either hydrophobic (H) or polar (P)

Optimal Sequence Each residual has a “solvent area” Want to reduce solvent areas of Hs Want to increase pairs of Hs in close contacts

Optimal Sequence Assign H, P to the residuals to minimize d(i,j): 1 if H at position i and H at position j is close enough, 0 otherwise s(i) : area exposed at position i

Problem 2: Forest Clearence profit for cutting trees cannot clear two adjacent square! which squares to clear to maximize profit?

Problem 3: All-Pair Maximum Bottleneck Bandwidth Path Given a graph, how to find the maximum bottleneck bandwidth path between any two nodes, u and v, efficiently?