1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.

Slides:



Advertisements
Similar presentations
6.896: Topics in Algorithmic Game Theory Lecture 21 Yang Cai.
Advertisements

Lecture 15. Graph Algorithms
Great Theoretical Ideas in Computer Science
Greedy Algorithms Greed is good. (Some of the time)
Great Theoretical Ideas in Computer Science for Some.
Chen, Lu Mentor: Zhou, Jian Shanghai University, School of Management Chen213.shu.edu.cn.
Minimum Spanning Tree CSE 331 Section 2 James Daly.
Great Theoretical Ideas in Computer Science.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Discussion #36 Spanning Trees
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
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.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
Great Theoretical Ideas in Computer Science.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
CSE 326: Data Structures Spanning Trees Ben Lerner Summer 2007.
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.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
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.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 8 Greedy Graph.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
10.4 How to Find a Perfect Matching We have a condition for the existence of a perfect matching in a graph that is necessary and sufficient. Does this.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 10.
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
10.3 The Main Theorem. Theorem (The Marriage Theorem) A bipartite graph has a perfect matching if and only if IAI = IBI and for any subset of (say)
Lectures on Greedy Algorithms and Dynamic Programming
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
Models of Greedy Algorithms for Graph Problems Sashka Davis, UCSD Russell Impagliazzo, UCSD SIAM SODA 2004.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
Great Theoretical Ideas In Computer Science
COMP108 Algorithmic Foundations Greedy methods
Minimum Spanning Trees
Great Theoretical Ideas in Computer Science
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Chapter 5. Optimal Matchings
Short paths and spanning trees
Discrete Mathematics for Computer Science
Minimum-Cost Spanning Tree
Spanning Trees.
Minimum Spanning Tree.
Spanning Trees.
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
Hannah Tang and Brian Tjaden Summer Quarter 2002
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
CSE 373: Data Structures and Algorithms
CSE 417: Algorithms and Computational Complexity
Minimum Spanning Trees (MSTs)
The Greedy Approach Young CS 530 Adv. Algo. Greedy.
CSE 373: Data Structures and Algorithms
Lecture 14 Minimum Spanning Tree (cont’d)
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Minimum Spanning Trees
Presentation transcript:

1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320

2 Reminder: Spanning Trees A spanning tree of a graph G is a tree that touches every node of G and uses only edges from G Problem: Find a minimum spanning tree, that is, a tree that has a node for every node in the graph, such that the sum of the edge weights is minimum

3 Finding a MST: Kruskal’s Algorithm Create a forest where each node is a separate tree Make a sorted list of edges S While S is non-empty: Remove an edge with minimal weight If it connects two different trees, add the edge. Otherwise discard it.

Applying the Algorithm

5 Greed is Good (In this case…) The greedy algorithm, by adding the least costly edges in each stage, succeeds in finding an MST Obviously greedy approaches do not work for all problems … Some examples where they do work?

6 Greedy Algorithms vs. Backtracking

7 Shortest-paths in a graph

8

9 Shortest path problem Input data: Directed graph: G= (V, E) Start and end node: s, t Length l e for each edge e Output: shortest path from s to t [cost of path = sum of all edges]

10 Dijkstra’s algorithm Idea: Maintain a set of explored nodes S for which we have determined the shortest path distance d(u) from s to u.

11 Dijkstra’s algorithm Idea: Maintain a set of explored nodes S for which we have determined the shortest path distance d(u) from s to u.  Initialize S = {s}, d(s) = 0.  Repeatedly choose unexplored node v to minimize add v to S, and set d(v) = π(v).  Until all nodes are chosen Shortest path from a node in u to any other unexplored node

12 Example

13 Dijkstra: Complexity analysis  Initialize S = {s}, d(s) = 0.  Repeatedly choose unexplored node v to minimize add v to S, and set d(v) = π(v).

14 Bipartite Graphs A graph is bipartite if the nodes can be partitioned into two sets V 1 and V 2 such that all edges go only between V 1 and V 2 (no edges go from V 1 to V 1 or from V 2 to V 2 )

15 Dancing Partners A group of 100 boys and girls attend a dance. Every boy knows 5 girls, and every girl knows 5 boys. Can they be matched into dance partners so that each pair knows each other?

16 Dancing Partners

17 Perfect Matchings Perfect Matching: A matching that covers all nodes in the graph with one edge going to each node. Theorem: If every node in a bipartite graph has the same degree d  1, then the graph has a perfect matching. Note: if degrees are the same then |A| = |B|, where A is the set of nodes “on the left” and B is the set of nodes “on the right”

18 If there are m boys, there are md edges If there are n girls, there are nd edges Proof: Claim: If all nodes have the same degree then |A| = |B| A Matter of Degree

19 The Marriage Theorem Theorem: A bipartite graph has a perfect matching if and only if |A| = |B| and for all k  [1,n]: for any subset of k nodes of A there are at least k nodes of B that are connected to at least one of them.

20 The condition fails for this graph The Marriage Theorem For any subset of (say) k nodes of A there are at least k nodes of B that are connected to at least one of them

21 k At most n-k n-k At least k The condition of the theorem still holds if we swap the roles of A and B: If we pick any k nodes in B, they are connected to at least k nodes in A The Feeling is Mutual

22 Proof Sketch of Marriage Theorem Call a bipartite graph “matchable” if it has the same number of nodes on left and right, and any k nodes on the left are connected to at least k on the right Strategy: Break up the graph into two matchable parts, and recursively partition each of these into two matchable parts, etc., until each part has only two nodes

23 Proof Sketch of Marriage Theorem Select two nodes a  A and b  B connected by an edge Idea: Take G 1 = (a,b) and G 2 = everything else Problem: G 2 need not be matchable. There could be a set of k nodes that has only k-1 neighbors.

24 k-1 k a b The only way this could fail is if one of the missing nodes is b This is a matchable partition! Sketch of Marriage Theorem Proof Add this in to form G 1, and take G 2 to be everything else.

25 More formally …

26 Generalized Marriage: Hall’s Theorem Let S = {S 1, S 2, …} be a set of finite subsets that satisfies: For any subset T = {T i } of S, |  T i |  |T|. Thus, any k subsets contain at least k elements Then we can choose an element x i  S i from each S i so that {x 1, x 2, …} are all distinct

27 Suppose that a standard deck of cards is dealt into 13 piles of 4 cards each Then it is possible to select a card from each pile so that the 13 chosen cards contain exactly one card of each rank Example

28 Here’s What You Need to Know… Minimum Spanning Tree - Definition Kruskal’s Algorithm - Definition - Proof of Correctness Dijkstra’s algorithm - algorithm - proof of correctness The Marriage Theorem