Depth-First Search Lecture 21: Graph Traversals

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

© 2004 Goodrich, Tamassia Depth-First Search1 DB A C E.
Depth-First Search1 Part-H2 Depth-First Search DB A C E.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
CSC401 – Analysis of Algorithms Lecture Notes 14 Graph Biconnectivity
Graphs – Depth First Search ORD DFW SFO LAX
© 2004 Goodrich, Tamassia Breadth-First Search1 CB A E D L0L0 L1L1 F L2L2.
Graph Searching CSE 373 Data Structures Lecture 20.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Breadth-First Search Seminar – Networking Algorithms CS and EE Dept. Lulea University of Technology 27 Jan Mohammad Reza Akhavan.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 8, Part I Graph Algorithms.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 27 Graph Applications.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Graph Searching (Graph Traversal) Algorithm Design and Analysis Week 8 Bibliography: [CLRS] – chap 22.2 –
Depth-First Search1 DB A C E. 2 Outline and Reading Definitions (§6.1) Subgraph Connectivity Spanning trees and forests Depth-first search (§6.3.1) Algorithm.
Data Structures & Algorithms Graph Search Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graph Traversals Reading Material: Chapter 9. Graph Traversals Some applications require visiting every vertex in the graph exactly once. The application.
Breadth-First Search1 Part-H3 Breadth-First Search CB A E D L0L0 L1L1 F L2L2.
© 2004 Goodrich, Tamassia Depth-First Search1 DB A C E.
TTIT33 Alorithms and Optimization – DALG Lecture 4 Graphs HT TTIT33 Algorithms and optimization Algorithms Lecture 4 Graphs.
Graph Traversals CSC 172 SPRING 2002 LECTURE 26. Traversing graphs Depth-First Search like a post-order traversal of a tree Breath-First Search Less like.
Applications of Depth-First Search
1 Graphs: Concepts, Representation, and Traversal CSC401 – Analysis of Algorithms Lecture Notes 13 Graphs: Concepts, Representation, and Traversal Objectives:
Graph Traversals CSC 172 SPRING 2004 LECTURE 21. Announcements  Project 3 is graded  handed back Tuesday  Grad spam, tonight – if you are really anxious.
CSC311: Data Structures 1 Chapter 13: Graphs I Objectives: Graph ADT: Operations Graph Implementation: Data structures Graph Traversals: DFS and BFS Directed.
TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 11 – Graphs Graphs HT TDDB56 – DALGOPT-D Algorithms and optimization Lecture 11 Graphs.
1 Graph Algorithms Lecture 09 Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information and Computer Technology.
CSC 213 – Large Scale Programming. Today’s Goals  Make Britney sad through my color choices  Revisit issue of graph terminology and usage  Subgraphs,
Graphs Part 1. Outline and Reading Graphs (§13.1) – Definition – Applications – Terminology – Properties – ADT Data structures for graphs (§13.2) – Edge.
October 22, DFS, BFS, Biconnectivity, Digraphs 1 CS 221 West Virginia University.
1 Applications of BFS and DFS CSE 2011 Winter May 2016.
GRAPHS 1. Outline 2  Undirected Graphs and Directed Graphs  Depth-First Search  Breadth-First Search.
1 prepared from lecture material © 2004 Goodrich & Tamassia COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material.
Artificial Intelligence LECTURE 4 ARTIFICIAL INTELLIGENCE LECTURES BY ENGR. QAZI ZIA.
ADA: 9. Graph Search1 Objective o describe and compare depth-first and breadth- first graph searching, and look at the creation of spanning trees.
Depth-First Search1 DB A C E. 2 Depth-first search (DFS) is a general technique for traversing a graph A DFS traversal of a graph G – Visits all the vertices.
1 Subgraphs A subgraph S of a graph G is a graph such that The vertices of S are a subset of the vertices of G The edges of S are a subset of the edges.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs. Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A,
Introduction to Graph Theory Lecture 17: Graph Searching Algorithms.
Graphs & Paths Presentation : Part II. Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent.
Graphs and Paths : Chapter 15 Saurav Karmakar
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.
© 2010 Goodrich, Tamassia Breadth-First Search1 CB A E D L0L0 L1L1 F L2L2.
Graphs ORD SFO LAX DFW Graphs 1 Graphs Graphs
Breadth-First Search L0 L1 L2
Searching Graphs ORD SFO LAX DFW Spring 2007
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Breadth-First Search L0 L1 L2
Chapter 14 Graph Algorithms
CS120 Graphs.
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Depth-First Search D B A C E Depth-First Search Depth-First Search
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Depth-First Search D B A C E Depth-First Search Depth-First Search
Elementary Graph Algorithms
Depth-First Search D B A C E Depth-First Search Depth-First Search
Graphs ORD SFO LAX DFW Graphs Graphs
Subgraphs, Connected Components, Spanning Trees
Searching Graphs ORD SFO LAX DFW Spring 2007
Copyright © Aiman Hanna All rights reserved
Depth-First Search D B A C E 4/13/2019 5:23 AM Depth-First Search
Algorithms: Design and Analysis
Breadth-First Search L0 L1 L2 C B A E D F 4/25/2019 3:12 AM
Breadth-First Search L0 L1 L2 C B A E D F 5/14/ :22 AM
Breadth-First Search L0 L1 L2 C B A E D F 7/28/2019 1:03 PM
Presentation transcript:

Depth-First Search Lecture 21: Graph Traversals 4/26/2017 10:14 AM CSC 213 Lecture 21: Graph Traversals C B A E D L0 L1 F L2 C B A E D F

Subgraphs A subgraph S of a graph G is a graph such that Depth-First Search 4/26/2017 10:14 AM Subgraphs A subgraph S of a graph G is a graph such that All edges & vertices in S also exist within G Spanning subgraph of G contains all of G’s vertices Subgraph Spanning subgraph

Graph with two connected components Depth-First Search 4/26/2017 10:14 AM Connectivity Graph is connected path exists between every pair of vertices Does not require an edge between all vertices, however Connected component is a maximal connected subgraph So you could not add another connected node to the subgraph Connected graph Graph with two connected components

Tree Tree is a graph Forest is graph containing a number of trees Depth-First Search 4/26/2017 10:14 AM Tree Tree is a graph Must be undirected Must be connected Cannot contain a cycle Forest is graph containing a number of trees Tree Forest

Depth-First Search 4/26/2017 10:14 AM Spanning Tree Spanning tree of a connected graph is a subgraph containing every vertex and no cycles Graph Spanning tree

Depth- & Breadth-First Search Depth-First Search 4/26/2017 10:14 AM Depth- & Breadth-First Search Common techniques to traverse a graph DFS and BFS traversal of a graph G Visits all vertices and edges in G Computes if G is connected and, if it is not, finds connected components Computes spanning tree/spanning forest They help solve many graph problems

DFS and Maze Traversal Classic strategy for exploring maze Depth-First Search 4/26/2017 10:14 AM DFS and Maze Traversal Classic strategy for exploring maze Mark the intersections, corners and dead ends visited We mark corridors (edges) followed Can follow lines to get back to where we started the maze

Example unexplored vertex visited vertex unexplored edge Depth-First Search 4/26/2017 10:14 AM Example unexplored vertex D B A C E A A visited vertex unexplored edge discovery edge back edge D B A C E A B D E C

Example (cont.) D B A C E D B A C E D B A C E D B A C E Depth-First Search 4/26/2017 10:14 AM Example (cont.) D B A C E D B A C E D B A C E D B A C E

Properties of DFS Property 1 Property 2 Depth-First Search 4/26/2017 10:14 AM Properties of DFS Property 1 Visits all vertices and edges within a connected component Property 2 Edges followed during the depth-first search form a spanning tree for the connected component D B A C E

Visitor Pattern Another commonly used coding method Depth-First Search 4/26/2017 10:14 AM Visitor Pattern Another commonly used coding method Often uses DFS as a Template Method Defines at least 5 methods: initResult() – called at start of traversal startVisit() – called at start of vertex (node) processing 1 or more methods to analyze data during the traversal finishVisit() – called at end of vertex processing result() – called to get result of traversal

Example unexplored vertex visited vertex unexplored edge Depth-First Search 4/26/2017 10:14 AM Example C B A E D L0 L1 F A unexplored vertex A visited vertex unexplored edge discovery edge cross edge L0 L0 A A L1 L1 B C D B C D E F E F

Example (cont.) L0 L1 L0 L1 L2 L0 L1 L2 L0 L1 L2 C B A E D F C B A E D Depth-First Search 4/26/2017 10:14 AM Example (cont.) C B A E D L0 L1 F C B A E D L0 L1 F L2 C B A E D L0 L1 F L2 C B A E D L0 L1 F L2

Example (cont.) L0 L1 L2 L0 L1 L2 L0 L1 L2 C B A E D F A B C D E F C B Depth-First Search 4/26/2017 10:14 AM Example (cont.) C B A E D L0 L1 F L2 L0 A L1 B C D L2 E F C B A E D L0 L1 F L2

Properties of BFS Property 1 Property 2 Property 3 Depth-First Search 4/26/2017 10:14 AM Properties of BFS Property 1 Visits all the vertices and edges within connected component Property 2 Discovery edges form a spanning tree of the component Property 3 For each vertex v in Li Path from s to v in spanning tree has exactly i edges Paths from s to v in G has at least i edges A B C D E F L0 A L1 B C D L2 E F

DFS vs. BFS Applications DFS BFS DFS BFS Depth-First Search 4/26/2017 10:14 AM DFS vs. BFS Applications DFS BFS Spanning forest, connected components, paths, cycles  Shortest paths Biconnected components C B A E D L0 L1 F L2 A B C D E F DFS BFS

DFS vs. BFS (cont.) Back edge (v,w) Cross edge (v,w) DFS BFS Depth-First Search 4/26/2017 10:14 AM DFS vs. BFS (cont.) Back edge (v,w) w is an ancestor of v in the tree of discovery edges Cross edge (v,w) w is in the same level as v or in the next level in the tree of discovery edges C B A E D L0 L1 F L2 C B A E D F DFS BFS