Podcast Ch24b Title: Strongly Connected Components

Slides:



Advertisements
Similar presentations
Topological Sort Topological sort is the list of vertices in the reverse order of their finishing times (post-order) of the depth-first search. Topological.
Advertisements

Elementary Graph Algorithms Depth-first search.Topological Sort. Strongly connected components. Chapter 22 CLRS.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 24 Graphs.
Algoritma Traversal Graph. Graph Traversal Algorithms In general, graphs do not have a vertex, like a root, that initiates unique paths to each of the.
Directed Graphs. Given vertices u and v of a digraph G , we say that u reaches v (and v is reachable from u ) if G  has a directed path from u to.
Lecture 10 Topics Application of DFS Topological Sort
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Depth-First Search Idea: Keep going forward as long as there are unseen nodes to be visited. Backtrack when stuck. v G G G G is completely traversed.
1 Graphs & Characteristics Graph Representations A Representation in C++ (Ford & Topp) Searching (DFS & BFS) Connected Components Graph G and Its Transpose.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 25 Graph.
Data Structures & Algorithms Graphs. Graph Terminology A graph consists of a set of vertices V, along with a set of edges E that connect pairs of vertices.
Algorithm for obtaining the connected components of a graph Samia Qader 252a-az HW # 6 all examples obtained from LEDA software in directory: 252a/handout/demo/graphwin/graphwin.
– Graphs 1 Graph Categories Strong Components Example of Digraph
7. Graph Traversal Describe and compare depth-first and breadth-first graph searching, and look at the creation of spanning trees Contest Algorithms: 7.
Strongly Connected Components for Directed Graphs Kelley Louie Credits: graphs by /demo/graphwin/graphwin.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
Podcast Ch24c Title: Breadth First Search
Breadth-First Search (BFS)
Podcast Ch23e Title: Implementing Huffman Compression
Podcast Ch17b Title: Iterative Tree Traversal
Tracing An Algorithm for Strongly Connected Components that uses Depth First Search Graph obtained from Text, page a-al: Geetika Tewari.
Depth First Search Neil Tang 4/1/2010
Podcast Ch24d Title: Depth First Search and Acyclic Graphs
Undirected versus Directed Graphs
Main algorithm with recursion: We’ll have a function DFS that initializes, and then calls DFS-Visit, which is a recursive function and does the depth first.
Chapter 3. Decompositions of Graphs
Podcast Ch26a Title: Representing Graphs
Podcast Ch17a Title: Expression Trees
Data Structures for Java William H. Ford William R. Topp
Graphs Graph transversals.
Lecture 10 Algorithm Analysis
Advanced Algorithms Analysis and Design
Applications of DFS Topological sort (for directed acyclic graph)
Analysis of Algorithms CS 477/677
Depth-First Search D B A C E Depth-First Search Depth-First Search
Podcast Ch25d Title: Minimum Path Algorithm
Podcast Ch18b Title: STree Class
Graphs Part 2 Adjacency Matrix
Podcast Ch24b Title: Graphs and Digraphs
Data Structures & Algorithms
Depth-First Search D B A C E Depth-First Search Depth-First Search
Podcast Ch22c Title: Deleting from a Heap
Podcast Ch23b Title: BitArray Implementation
Podcast Ch18c Title: BST delete operation
Podcast Ch25c Title: Shortest Path Algorithm
Podcast Ch23f Title: Serialization
Depth First Search Neil Tang 4/10/2008
Depth-First Search CSE 2011 Winter April 2019.
Algorithms: Design and Analysis
Text Book: Introduction to algorithms By C L R S
Podcast Ch22b Title: Inserting into a Heap
Depth-First Search CSE 2011 Winter April 2019.
Podcast Ch18a Title: Overview of Binary Search Trees
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Chapter 16 1 – Graphs Graph Categories Strong Components
Podcast Ch20b Title: TreeMap Design
Podcast Ch18d Title: Binary Search Tree Iterator
Podcast Ch21d Title: Hash Class Iterators
Podcast Ch26b Title: Digraph Class Implementation
Podcast Ch27a Title: Overview of AVL Trees
Data structure for graph algorithms: Adjacent list, Adjacent matrix
Podcast Ch21f Title: HashSet Class
Podcast Ch23d Title: Huffman Compression
Podcast Ch27b Title: AVLTree implementation
Podcast Ch22a Title: Array-based Binary Trees
Podcast Ch21b Title: Collision Resolution
Podcast Ch23a Title: Bit Arrays
Presentation transcript:

Podcast Ch24b Title: Strongly Connected Components Description: Overview of strongly connected components; strongComponents method Participants: Barry Kurtz (instructor); John Helfert and Tobie Williams (students) Textbook: Data Structures for Java; William H. Ford and William R. Topp

Strongly Connected Components Any graph can be partitioned into a unique set of strong components.

Student Question What are the strong components in graph G?

Strongly Connected Components (continued) The algorithm for finding the strong components of a directed graph G uses the transpose of the graph. The transpose GT has the same set of vertices V as graph G but a new edge set consisting of the edges of G but with the opposite direction.

Strongly Connected Components (continued) Execute the depth-first search dfs() for the graph G which creates the list dfsList consisting of the vertices in G in the reverse order of their finishing times. Generate the transpose graph GT. Using the order of vertices in dfsList, make repeated calls to dfsVisit() for vertices in GT. The list returned by each call is a strongly connected component of G.

Strongly Connected Components (continued)

Strongly Connected Components (continued) dfsList: [A, B, C, E, D, G, F] Using the order of vertices in dfsList, make successive calls to dfsVisit() for graph GT Vertex A: dfsVisit(A) returns the list [A, C, B] of vertices reachable from A in GT. Vertex E: The next unvisited vertex in dfsList is E. Calling dfsVisit(E) returns the list [E]. Vertex D: The next unvisited vertex in dfsList is D; dfsVisit(D) returns the list [D, F, G] whose elements form the last strongly connected component.

strongComponents() // find the strong components of the graph; // each element of component is a LinkedList // of the elements in a strong component public static <T> void strongComponents(DiGraph<T> g, ArrayList<LinkedList<T>> component) { T currVertex = null; // list of vertices visited by dfs() for graph g LinkedList<T> dfsList = new LinkedList<T>(); // list of vertices visited by dfsVisit() // for g transpose LinkedList<T> dfsGTList = null; // used to scan dfsList Iterator<T> gIter; // transpose of the graph DiGraph<T> gt = null;

strongComponents() (cont) // clear the return vector component.clear(); // execute depth-first traversal of g dfs(g, dfsList); // compute gt gt = transpose(g); // initialize all vertices to WHITE (unvisited) gt.colorWhite(); // call dfsVisit() for gt from vertices in dfsList gIter = dfsList.iterator(); while(gIter.hasNext()) { currVertex = gIter.next();

strongComponents() (concluded) // call dfsVisit() only if vertex // has not been visited if (gt.getColor(currVertex) == VertexColor.WHITE) { // create a new LinkedList to hold // next strong component dfsGTList = new LinkedList<T>(); // do dfsVisit() in gt for starting // vertex currVertex dfsVisit(gt, currVertex, dfsGTList, false); // add strong component to the ArrayList component.add(dfsGTList); }

Running Time of strongComponents() Recall that the depth-first search has running time O(V+E), and the computation for GT is also O(V+E). It follows that the running time for the algorithm to compute the strong components is O(V+E).

Student Question List the vertices in reverse order of finish time for a depth-first search of this digraph. dfsList: [ _________________________________________ ] Display the transpose of the graph. List the strong components by doing a depth-first search of the transpose in the order specified by your dfsList. _____________________________________________