Week 11 - Friday.  What did we talk about last time?  Exam 2 post mortem  Cycle detection  Connectivity.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Graph Algorithms
Advertisements

What is a graph ? G=(V,E) V = a set of vertices E = a set of edges edge = unordered pair of vertices
Piyush Kumar (Lecture 3: Stable Marriage) Welcome to COT5405.
Naveen Garg, CSE, IIT Delhi
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
Graphs – Depth First Search ORD DFW SFO LAX
Topics: 1. Finding a cycle in a graph 2. Propagation delay - example 3. Trees - properties מבנה המחשב - אביב 2004 תרגול 3#
Connected Components, Directed Graphs, Topological Sort COMP171.
Chapter 26 of CLSR Bipartite Matching By Dr. M. Sakalli, Sources: Levitin and many other CSE, Marmara Univ. May/2009.
Lecture 4 CSE 331 Sep 9, Blog posts for lectures Starts from today See Sep 8 post on the blog.
© 2004 Goodrich, Tamassia Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO.
1 Directed Graphs CSC401 – Analysis of Algorithms Lecture Notes 15 Directed Graphs Objectives: Introduce directed graphs and weighted graphs Present algorithms.
Connected Components, Directed Graphs, Topological Sort Lecture 25 COMP171 Fall 2006.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO. Directed Graphs2 Outline and Reading (§6.4) Reachability (§6.4.1) Directed DFS Strong connectivity Transitive.
מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3.
Connected Components, Directed graphs, Topological sort COMP171 Fall 2005.
D1: Matchings.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
Chapter 10: Iterative Improvement Simplex Method The Design and Analysis of Algorithms.
CSE, IIT KGP Matchings and Factors. CSE, IIT KGP Matchings A matching of size k in a graph G is a set of k pairwise disjoint edges.A matching of size.
Charles Lin. Graph Representation Graph Representation DFS DFS BFS BFS Dijkstra Dijkstra A* Search A* Search Bellman-Ford Bellman-Ford Floyd-Warshall.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar.
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
All Pair Shortest Path IOI/ACM ICPC Training June 2004.
Bipartite Matching. Unweighted Bipartite Matching.
Week 12 - Monday.  What did we talk about last time?  Topological sort and cycle detection in directed graphs  Connectivity  Strong connectivity.
Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
DIRECTED ACYCLIC GRAPHS AND TOPOLOGICAL SORT CS16: Introduction to Data Structures & Algorithms Tuesday, March 10,
DATA STRUCTURES AND ALGORITHMS Lecture Notes 10 Prepared by İnanç TAHRALI.
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
Week 11 - Friday.  What did we talk about last time?  Exam 2 post mortem  Cycle detection in undirected graphs  Topological sort and cycle detection.
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
CS 367 Introduction to Data Structures Lecture 13.
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Matchings and Factors Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering,
Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO. Directed Graphs2 Outline and Reading (§12.4) Reachability (§12.4.1) Directed DFS Strong connectivity Transitive.
Week 11 - Wednesday.  What did we talk about last time?  Exam 2  And before that:  Graph representations  Depth first search.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Stable Matching Beyond Bipartite Graphs Jie Wu Dept. of Computer and Info. Sciences Temple University.
Week 6 - Monday.  What did we talk about last time?  Artificial intelligence  Lab 5.
IOI/ACM ICPC Training 4 June 2005.
Matching Boys Girls A B C D E
Stable Marriage Problem
Chapter 10 Iterative Improvement
Week 6 - Wednesday CS 113.
Maximum Flow - Best algorithms
Special Graphs: Modeling and Algorithms
Various Graph Algorithms
Bipartite Matching and Other Graph Algorithms
CS120 Graphs.
Graph Search Applications
Lecture 5 CSE 331 Sep 10, 2010.
"Learning how to learn is life's most important skill. " - Tony Buzan
Topological Sort CSE 373 Data Structures Lecture 19.
Lectures on Graph Algorithms: searching, testing and sorting
Richard Anderson Autumn 2016 Lecture 5
Richard Anderson Winter 2009 Lecture 6
Piyush Kumar (Lecture 3: Stable Marriage)
Richard Anderson Winter 2019 Lecture 6
Richard Anderson Lecture 5 Graph Theory
Richard Anderson Winter 2019 Lecture 5
Week 10 - Wednesday CS221.
Richard Anderson Autumn 2015 Lecture 6
Lecture 27: More Graph Algorithms
Presentation transcript:

Week 11 - Friday

 What did we talk about last time?  Exam 2 post mortem  Cycle detection  Connectivity

Spellchecker

 Connected for an undirected graph: There is a path from every node to every other node  How can we determine if a graph is connected?

 Startup 1. Set the number of all nodes to 0 2. Pick an arbitrary node u and run DFS( u, 1 )  DFS( node v, int i ) 1. Set number(v) = i++ 2. For each node u adjacent to v If number(u) is 0 DFS( u, i )  If any node has a number of 0, the graph is not connected

 Weakly connected directed graph: If the graph is connected when you make all the edges undirected  Strongly connected directed graph: If for every pair of nodes, there is a path between them in both directions

 Components of a directed graph can be strongly connected  A strongly connected component is a subgraph such that all its nodes are strongly connected  To find strongly connected components, we can use a special DFS  It includes the notion of a predecessor node, which is the lowest numbered node in the DFS that can reach a particular node

 StrongDFS( node v, int i ) 1. Set number(v) = i++ 2. Set predecessor(v) to number(v) 3. Push(v) 4. For each node u adjacent to v If number(u) is 0 StrongDFS( u, i ) predecessor(v) = min(predecessor(v), predecessor(u)) Else if number(u) < number(v) and u is 0n the stack predecessor(v) = min(predecessor(v), number(u)) 5. If predecessor(v) is number(v) w = pop() while w is not v output w w = pop() output w

 StronglyConnected( Vertices V )  Set i = 1  For each node v in V Set number(v) = 0  For each node v in V If number(v) is 0 StrongDFS( v, i )

A B I D F H C E G

Student Lecture

 A directed acyclic graph (DAG) is a directed graph without cycles in it  Well, obviously  These can be used to represent dependencies between tasks  An edge flows from the task that must be completed first to a task that must come after  This is a good model for course sequencing  Especially during advising  A cycle in such a graph would mean there was a circular dependency

 A topological sort gives an ordering of the tasks such that all tasks are completed in dependency ordering  In other words, no task is attempted before its prerequisite tasks have been done  There are usually multiple legal topological sorts for a given DAG

 Give a topological sort for the following DAG:  A F I C G K D J E H A A H H E E J J D D K K G G C C F F I I

 Create list L  Add all nodes with no incoming edges into set S  While S is not empty  Remove a node u from S  Add u to L  For each node v with an edge e from u to v ▪ Remove edge e from the graph ▪ If v has no other incoming edges, add v to S  If the graph still has edges  Print "Error! Graph has a cycle"  Otherwise  Return L

 A bipartite graph is one whose nodes can be divided into two disjoint sets X and Y  There can be edges between set X and set Y  There are no edges inside set X or set Y  A graph is bipartite if and only if it contains no odd cycles

A A B B C C D D E E F F A A B B C C D D E E F F X Y

 A perfect matching is when every node in set X and every node in set Y is matched  It is not always possible to have a perfect matching  We can still try to find a maximum matching in which as many nodes are matched up as possible

1. Come up with a legal, maximal matching 2. Take an augmenting path that starts at an unmatched node in X and ends at an unmatched node in Y 3. If there is such a path, switch all the edges along the path from being in the matching to being out and vice versa 4. If there is another augmenting path, go back to Step 2

A A B B C C D D E E F F A A B B C C D D E E F F X Y Anna Becky CaitlinDaisyErinFiona Adam Ben CarlosDanEvanFred

 All 2n people want to get married  Each woman has ranked all n men in order of preference  Each man has ranked all n women in order of preference  We want to match them up so that the marriages are stable

 Consider two marriages:  Anna and Bob  Caitlin and Dan  This pair of marriages is unstable if  Anna likes Dan more than Bob and Dan likes Anna more than Caitlin or  Caitlin likes Bob more than Dan and Bob likes Caitlin more than Anna  We want to arrange all n marriages such that none are unstable

 n rounds  In each round, every unengaged man proposes to the woman he likes best (who he hasn’t proposed to already)  An unengaged woman must accept the proposal from the one of her suitors she likes best  If a woman is already engaged, she accepts the best suitor only if she likes him better than her fiance

 It’s a graph problem where we never look at a graph  The algorithm is guaranteed to terminate  A woman can’t refuse to get engaged  If a man gets dumped, he will eventually propose to everyone  The algorithm is guaranteed to find stable marriages  Unfortunately, it’s male-optimal and female- pessimal  The lesson: Women should propose to men

 Finish matching and stable marriage  Euler paths and tours

 Finish Project 3  Due tonight before midnight  Start Assignment 6  Due next Friday  Keep reading Chapter 8