1 / 21

CS 312: Algorithm Analysis

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License . CS 312: Algorithm Analysis. Lecture #16: Strongly Connected Components. Slides by: Eric Ringger, adapting figures from Dasgupta et al. Objectives. Understand how to linearize a DAG

nancy
Download Presentation

CS 312: Algorithm Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. CS 312: Algorithm Analysis Lecture #16: Strongly Connected Components Slides by: Eric Ringger, adapting figures from Dasgupta et al.

  2. Objectives • Understand how to linearize a DAG • Introduce the idea of connectedness among vertices in Directed Graphs • Introduce the algorithm for finding Strongly Connected Components

  3. Cycles • How do you detect a cycle in a directed graph? • Property: A directed graph has a cycle if and only if its depth-first search reveals a back edge. • Otherwise: a Directed Acyclic Graph (DAG)

  4. Sources, Sinks, Linearization DFS Search Forest: Linearized DAG: Analysis: 0. Define order; 1. DFS; 2. Read off post-order values in reverse order

  5. Sources, Sinks, Linearization • Property: In a DAG, every edge leads to a vertex with a smaller post number. • Property: Every DAG has at least one source (a node with 0 in-degree). • Property: Every DAG has at least one sink (a node with 0 out-degree). • How to prove these?

  6. Many Kinds of Connectedness Graphs Undirected Directed Edge Edge Vertex Vertex Strongly connected components Similar to biconnected components Connected components Biconnected components

  7. Connectivity in Directed Graphs • Two nodes u and v of a directed graph are connectediff there is a path from u to v and a path from v to u. • Each vertex v is connected to itself. • Defines an equivalence relation! • This relation partitions V into disjoint sets that we call strongly connected components. • Equivalence classes under the above relation

  8. Example Meta-graph:

  9. Meta-Graph

  10. Meta-Graph Property: Every directed graph is a DAG of its strongly connected components.

  11. How would you find SCCs?

  12. How would you find SCCs? • Idea 1: run DFS, identify back-edges to find cycles, post-process • Idea 2: run DFS, identify back-edges to find cycles, merge cycles • How to analyze? • We’re going to go take a different direction …

  13. Finding Strongly Connected Components • To understand the algorithm for finding SCCs, you need to understand the following: • Pre and post numbering in DFS • Meta-graph created by representing each SCC with a single meta-node. • The meta-graph is a DAG and could therefore be linearized using DFS.

  14. Finding SCCs • Goal: Given a directed graph, find all of the SCCs • Big Idea: • A: Find a (vertex in a) sink SCC • B: Work back to find the other SCCs • How do you find a sink SCC? • Finding a sink (node) in a DAG is easy • But what about when there are cycles? • Problem A seems hard, so solve problem A’ first: • Finding a node in a source SCC of a directed graph could be easier. • A’: find a source SCC on the “reverse graph”

  15. Reverse Graph GR Metagraph of GR G To find a sink, identify a source SCC of the reverse graph GR!

  16. Insights • Property: The node that receives the highest post number in a depth-first search must lie in a source strongly connected component. • Property: If C and C’ are strongly connected components, and there is an edge from a node in C to a node in C’, then the highest post number in C is bigger than the highest post number in C’. • Consequence: The strongly connected components can be linearized by arranging them in decreasing order of their post numbers.

  17. Step 1 • Reverse the graph to produce GR • Necessary to do the reversal explicitly? • Run depth-first search on GR

  18. Problem 3.4 (ii)

  19. Step 2 • How do we continue once a vertex belonging to the sink component has been discovered? • Recall: The strongly connected components can be linearized by arranging them in decreasing order of their post numbers. • Run DFS on G, keeping track of connected components • Process the vertices beginning and breaking ties using the decreasing order of their post numbers from step 1 • Can neglect keeping pre and post numbers this time • Can neglect back-, cross-, and forward- edges this time as well

  20. 3 Questions • Is it correct? • Relies on the correctness of the properties we identified earlier • How long does it take? • 2 DFS passes • O(||V|| + ||E||) – again! • Can we do better?

  21. Assignment • HW #11: • Practice using the SCC-finding algorithm • Study for Midterm (Study Guide) • Testing Center: Tuesday-Thurs (10-12 July) • One page of notes hand written or typed by you • Read 4.1-4.7 • Shortest Paths • Breadth First Search • Dijkstra’s Algorithm

More Related