1 CS Lunch Interested in graduate school in CS? Wednesday, 12:20 to 1:20 Jaemarie Solyst Emilyann Nault Ammal Abbasi Ana Berthel Also, a presentation about the Master’ s in Cyber Security at WPI 2 Party Problem You want to throw a party at which there are no pairs of guests that do not get along. You want to invite as many guests as possible. How would you solve this? The party problem 3 Represent each guest as a node Draw an edge between guests who do not get along Find the largest set of nodes where there is no edge between any pair of nodes in the set Brenda Cheryl Alice Freida Dorothy Greta Eunice Slides07 - Directed graphs.key - February 13, 2019
4 Bipartite Graphs A bipartite graph is an undirected graph G = (V, E) in which the nodes can be colored red or blue such that every edge has one red and one blue end. is a bipartite graph is NOT a bipartite graph 5 A bipartite solution Brenda Cheryl Alice Freida Dorothy Greta Eunice 6 A bipartite solution Brenda Cheryl Alice Freida Dorothy Greta Eunice Slides07 - Directed graphs.key - February 13, 2019
7 A bipartite solution Brenda Cheryl Alice Freida Dorothy Greta Eunice 8 A bipartite solution Brenda Cheryl Alice Freida Dorothy Greta Eunice 9 A bipartite solution Brenda Cheryl Alice Freida Dorothy Greta Eunice Slides07 - Directed graphs.key - February 13, 2019
10 A bipartite solution Brenda Cheryl Alice Freida Dorothy Greta Eunice 11 A bipartite solution Brenda Cheryl Alice Freida Dorothy Greta Eunice 12 A bipartite solution Brenda Cheryl Alice Freida Dorothy Greta Eunice Who should you invite? Slides07 - Directed graphs.key - February 13, 2019
13 BFS and Bipartite Graphs Lemma. Let G be a connected graph, and let L 0 , …, L k be the layers produced by BFS starting at node s. Exactly one of the following holds. (i) No edge of G joins two nodes of the same layer, and G is bipartite. (ii) An edge of G joins two nodes of the same layer, and G contains an odd-length cycle (and hence is not bipartite). Brenda Eunice Alice Dorothy Freida Greta Cheryl Layer 4 Layer 2 Layer 3 Layer 0 Layer 1 14 BFS and Bipartite Graphs Lemma. Let G be a connected graph, and let L 0 , …, L k be the layers produced by BFS starting at node s. Exactly one of the following holds. (i) No edge of G joins two nodes of the same layer, and G is bipartite. (ii) An edge of G joins two nodes of the same layer, and G contains an odd-length cycle (and hence is not bipartite). Brenda Eunice Alice Dorothy Freida Greta Cheryl Layer 3 Layer 4 Layer 1 Layer 2 Layer 0 15 Directed Graphs Directed graph. G = (V, E) Edge (u, v) goes from node u to node v. Example: Web graph - hyperlink points from one web page to another. Directedness of graph is crucial. Modern web search engines exploit hyperlink structure to rank web pages by importance. 1 2 3 4 5 1 2 1 0 1 0 1 1 2 0 0 1 1 0 3 3 0 0 0 0 0 4 0 0 0 0 0 5 4 5 0 0 1 0 0 Slides07 - Directed graphs.key - February 13, 2019
16 Adjacency List 1 2 Store the edges in 3 the list in the direction that the 5 4 edge points TO 1 2 4 5 2 3 4 3 4 5 3 17 Finding Paths 1 2 3 5 4 Use BFS or DFS TO No guarantee that there is a reverse 1 2 4 5 path 2 3 4 3 4 5 3 18 Strong Connectivity Node u and v are mutually reachable if there is a path from u to v and also a path from v to u. A graph is strongly connected if every pair of nodes is mutually reachable. 1 2 is strongly connected. 3 5 4 1 2 is NOT strongly connected. 3 5 4 Slides07 - Directed graphs.key - February 13, 2019
19 Strong Connectivity Lemma. Let s be any node. G is strongly connected iff every node is reachable from s, and s is reachable from every node. Proof? 20 Directed Acyclic Graphs A directed acyclic graph (DAG) is a directed graph that contains no directed cycles. 1 2 is a DAG 3 5 4 1 2 is NOT a DAG 3 5 4 21 Directed Acyclic Graphs Uses for DAGs: Derives-from: You must buy food in order to make dinner. Timing: You should finish your homework before it is due. Is-bigger-than, is-faster-than, ... Any relationship that imposes a partial order. Slides07 - Directed graphs.key - February 13, 2019
22 Topological Order A topological order of a directed graph G = (V, E) is an ordering of its nodes as v 1 , v 2 , …, v n so that for every edge (v i , v j ) we have i < j 1 2 DAG 3 5 4 DAG’ s Topological 1 2 5 3 4 Ordering 23 Computing the Topological Order Lemma. If G is a DAG, then G has a node with no incoming edges. 1 2 3 5 4 Proof? 24-1 Algorithm topological-order(v) { find a node v with no incoming edges delete v from G return v followed by topological-order (G - {v}) } 1 2 3 5 4 Slides07 - Directed graphs.key - February 13, 2019
24-2 Algorithm topological-order(v) { find a node v with no incoming edges delete v from G return v followed by topological-order (G - {v}) } Step 1 1 2 2 3 3 5 4 5 4 24-3 Algorithm topological-order(v) { find a node v with no incoming edges delete v from G return v followed by topological-order (G - {v}) } Step 1 2 Step 2 1 2 2 3 3 3 5 4 5 4 4 24-4 Algorithm topological-order(v) { find a node v with no incoming edges delete v from G return v followed by topological-order (G - {v}) } Step 1 2 Step 2 1 2 2 3 3 3 5 4 5 4 4 Step 3 3 4 Slides07 - Directed graphs.key - February 13, 2019
24-5 Algorithm topological-order(v) { find a node v with no incoming edges delete v from G return v followed by topological-order (G - {v}) } Step 1 2 Step 2 1 2 2 3 3 3 5 4 5 4 4 Step 3 3 3 Step 4 4 24-6 Algorithm topological-order(v) { find a node v with no incoming edges delete v from G return v followed by topological-order (G - {v}) } Step 1 2 Step 2 1 2 2 3 3 3 5 4 5 4 4 Step 3 3 3 Step 4 Order: 1, 5, 2, 4, 3 4 Slides07 - Directed graphs.key - February 13, 2019
Recommend
More recommend