Depth First Search Neil Tang 4/10/2008

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

CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs CS-240/341. Graphs Used for representing many-to-many relationships –can take two forms directed (digraph) - a finite set of elements called vertices.
Graph Traversals Reading Material: Chapter 9. Graph Traversals Some applications require visiting every vertex in the graph exactly once. The application.
1 Topological Sort: DFS E C GFB AD A: BDFG B: C: D: E: E F: DE A E H H G: H:
1 Topological Sort: DFS F C G A B D E H. 2 F C G A B D E H dfs(A)
1 Directed Depth First Search Adjacency Lists A: F G B: A H C: A D D: C F E: C D G F: E: G: : H: B: I: H: F A B C G D E H I.
1 Directed Depth First Search Adjacency Lists A: F G B: A H C: A D D: C F E: C D G F: E: G: : H: B: I: H: F A B C G D E H I.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Breadth First Search and Depth First Search. Greatest problem in Computer Science Has lead to a lot of new ideas and data structures Search engines before.
Strongly Connected Components for Directed Graphs Kelley Louie Credits: graphs by /demo/graphwin/graphwin.
Graph Representations And Traversals. Graphs Graph : – Set of Vertices (Nodes) – Set of Edges connecting vertices (u, v) : edge connecting Origin: u Destination:
Hw. 6: Algorithm for finding strongly connected components. Original digraph as drawn in our book and in class: Preorder label : Postorder label Nodes:
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
CSC 172 DATA STRUCTURES.
BCA-II Data Structure Using C Submitted By: Veenu Saini
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
GRAPH TRAVERSING BY PROF. UZAIR SALMAN
Graphs Chapter 20.
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
Thinking about Algorithms Abstractly
A vertex u is reachable from vertex v iff there is a path from v to u.
Graphs-Part II Depth First Search (DFS)
Graphs Representation, BFS, DFS
Undirected versus Directed Graphs
Graph Traversals Some algorithms require that every vertex of a graph be visited exactly once. The order in which the vertices are visited may be important,
CC 215 Data Structures Graph Searching
CS223 Advanced Data Structures and Algorithms
Unweighted Shortest Path Neil Tang 3/11/2010
CS120 Graphs.
Spanning Trees Longin Jan Latecki Temple University based on slides by
Graph Algorithm.
Graphs Graph transversals.
Minimum Spanning Tree Neil Tang 3/25/2010
Graphs Chapter 13.
CS223 Advanced Data Structures and Algorithms
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Depth-First Search D B A C E Depth-First Search Depth-First Search
CS223 Advanced Data Structures and Algorithms
Undirected Depth First Search
Chapter 11 Graphs.
CSE 373 Data Structures Lecture 16
Spanning Trees Longin Jan Latecki Temple University based on slides by
Subgraphs, Connected Components, Spanning Trees
Depth-First Search D B A C E Depth-First Search Depth-First Search
Algorithms Lecture # 30 Dr. Sohail Aslam.
Minimum Spanning Tree Neil Tang 4/3/2008
Discrete Mathematics and
CS223 Advanced Data Structures and Algorithms
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
Algorithms Lecture # 29 Dr. Sohail Aslam.
Depth-First Search CSE 2011 Winter April 2019.
Algorithms: Design and Analysis
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Lecture 6 Graph Traversal
EMIS 8374 Search Algorithms Updated 9 February 2004
Depth-First Search CSE 2011 Winter April 2019.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
A vertex u is reachable from vertex v iff there is a path from v to u.
Chapter 16 1 – Graphs Graph Categories Strong Components
Spanning Trees Longin Jan Latecki Temple University based on slides by
Data structure for graph algorithms: Adjacent list, Adjacent matrix
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Prim’s Minimum Spanning Tree Algorithm Neil Tang 4/1/2008
CS203 Lecture 14.
EMIS 8374 Search Algorithms Updated 12 February 2008
Review for Final Neil Tang 05/01/2008
CMSC 341 Graphs.
Presentation transcript:

Depth First Search Neil Tang 4/10/2008 CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Class Overview Breadth First Search (BFS) Depth First Search (DFS) DFS on an undirected graph DFS on a digraph Strong connected components CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms BFS Visit the nodes that are one-hop away from the starting node one by one, then the nodes that are two-hop away, then … A queue should be used to implement the BFS. Make sure each node is visited exactly once. CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms DFS A generalized pre-order traversal Time Complexity: O(|V|+|E|) CS223 Advanced Data Structures and Algorithms

DFS on An Undirected Graph DFS(A): A,B,C,D,E CS223 Advanced Data Structures and Algorithms

DFS on An Undirected Graph DFS can be used to find if an undirected graph is connected or not. DFS can also be used to find all the connected components. CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms DFS on A Digraph DFS(B): B,C,A,D,E,F; DFS(H): H,J,I; DFS(G): G. CS223 Advanced Data Structures and Algorithms

Strong Connected Components Perform DFS until all nodes are visited. Construct an auxiliary graph Gr. Perform DFS on Gr in the reverse order of the numbers. CS223 Advanced Data Structures and Algorithms

Strong Connected Components Gr DFS(G): G; DFS(H): H,I,J; DFS(B): B,A,C,F; DFS(D): D; DFS(E): E. Strong Connected Components: (G), (H,I,J), (B,A,C,F),(D),(E) The spanning tree after the first DFS CS223 Advanced Data Structures and Algorithms