logistics
play

Logistics Quizzes Quiz 5: 74% Other quizzes: ~98% Ill drop lowest - PowerPoint PPT Presentation

Logistics Quizzes Quiz 5: 74% Other quizzes: ~98% Ill drop lowest 2 quizzes HW HW 2 back: average 44.9/50, 5.2 hours HW 3 due HW 4 out tonight No reading for Thursday Questions? Today BFS/DFS Connected components Bipartite testing


  1. Logistics Quizzes Quiz 5: 74% Other quizzes: ~98% I’ll drop lowest 2 quizzes HW HW 2 back: average 44.9/50, 5.2 hours HW 3 due HW 4 out tonight No reading for Thursday Questions?

  2. Today BFS/DFS Connected components Bipartite testing Directed Graphs

  3. Connected Components Definitions, example, proof on board

  4. “Meta”-BFS algorithm while there is an unexplored node s BFS(s) end Example Running time? argue O(m+n) running time on board

  5. Representing Graphs: Adjacency List Adjacency list. Each node keeps a (linked) list of neighbors. Find all edges incident to u: O(n u ) 1 2 4 5 1 2 2 1 3 4 3 3 2 5 4 1 2 5 4 5 1 3

  6. Running Time? Set explored[u] to be false for all u O(n) A = { s } / / set of discovered but not explored nodes while A is not empty O(m) Take a node u from A O(m) if explored[u] is false O(n) set explored[u] = true for each edge (u,v) incident to u add v to A O(m) end end end Same reasoning we just did: but now “charge” each line of code to either a node or an edge

  7. Graph Traversal: Summary BFS/DFS: O(n+m) Is G connected? Find connected components of G Find distance of every vertex from source Get BFS/DFS trees (useful in some other problems) BFS: explore by distance, layers, queue DFS: explore deeply, recursive, stack

  8. Application of BFS: Bipartite Testing

  9. 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 Examples? How can we check if a given graph is bipartite?

  10. Simple Observation: Odd Cycles Lemma. If G has a cycle of odd length, then G is not bipartite Proof on board

  11. 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).

  12. 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). Layer 4 Layer 3 Layer 2 Layer 1 Layer 0

  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). Layer 4 Layer 3 Layer 2 Layer 1 Layer 0

  14. Algorithm for Bipartite-Testing Run BFS Check each non-tree edge If any has endpoints in same layer, then G is not bipartite Otherwise, G is bipartite Running Time?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend