CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

© 2004 Goodrich, Tamassia Depth-First Search1 DB A C E.
CS203 Lecture 15.
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
Graph Traversals. For solving most problems on graphs –Need to systematically visit all the vertices and edges of a graph Two major traversals –Breadth-First.
Graphs – Depth First Search ORD DFW SFO LAX
© 2004 Goodrich, Tamassia Breadth-First Search1 CB A E D L0L0 L1L1 F L2L2.
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.
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.
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
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.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
1 Graphs: Concepts, Representation, and Traversal CSC401 – Analysis of Algorithms Lecture Notes 13 Graphs: Concepts, Representation, and Traversal Objectives:
Lecture 15: Depth First Search Shang-Hua Teng. Graphs G= (V,E) B E C F D A B E C F D A Directed Graph (digraph) –Degree: in/out Undirected Graph –Adjacency.
Graph Traversals CSC 172 SPRING 2004 LECTURE 21. Announcements  Project 3 is graded  handed back Tuesday  Grad spam, tonight – if you are really anxious.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 11 – Graphs Graphs HT TDDB56 – DALGOPT-D Algorithms and optimization Lecture 11 Graphs.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
1 Graph Algorithms Lecture 09 Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information and Computer Technology.
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
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.
1 Applications of BFS and DFS CSE 2011 Winter May 2016.
Elementary Graph Algorithms CLRS Chapter 22. Graph A graph is a structure that consists of a set of vertices and a set of edges between pairs of vertices.
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.
Depth-First Search Lecture 21: Graph Traversals
Introduction to Graph Theory Lecture 17: Graph Searching Algorithms.
Graphs and Paths : Chapter 15 Saurav Karmakar
CSC 252: Algorithms October 28, 2000 Homework #5: Graphs Victoria Manfredi (252a-ad) notes: -Definitions for each of the graph concepts are those presented.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Spanning Trees Alyce Brady CS 510: Computer Algorithms.
© 2010 Goodrich, Tamassia Breadth-First Search1 CB A E D L0L0 L1L1 F L2L2.
Graphs ORD SFO LAX DFW Graphs 1 Graphs Graphs
CSC 172 DATA STRUCTURES.
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
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
Depth-First Search Graph Traversals Depth-First Search DFS.
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
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:

CSC 213 – Large Scale Programming Lecture 31: Graph Traversals

Subgraphs Subgraph of a graph G must contain only edges & vertices from G Spanning subgraph contains all vertices from the graph Subgraph Spanning subgraph

Connected Graph Connected if path exists between every pair of vertices Requires a path, not an edge between vertices Connected component is subgraph containing all connected vertices Maximal connected Connected graph Graph with two connected components

Tree Connected, undirected, acyclic graph Just like Tree data structures Forest is graph containing multiple trees Tree Forest

Spanning Tree Subgraph that is spanning subgraph & tree Spanning subgraph  must contain all vertices Tree  must be connected without any cycles Spanning Tree

Depth- & Breadth-First Search Common graph traversal algorithms DFS & BFS traversals Visits all vertices and edges in G Computes if G is connected Finds connected components if G not connected Used frequently to solve graph problems

DFS and Maze Traversal Classic maze exploring strategy Each intersection, corner, & dead end is a vertex Corridors become edges DFS marks corridors traveled Marks lead back to start

DFS Example DB A C ED B A C E D B A C E discovery edge back edge A visited vertex A unexplored vertex unexplored edge

DFS Example (cont.) DB A C E DB A C E DB A C E D B A C E

Properties of DFS Visits all vertices and edges in a connected component Edges followed form a spanning tree for the connected component DB A C E

BFS Example C B A E D discovery edge cross edge A visited vertex A unexplored vertex unexplored edge L0L0 L1L1 F CB A E D L0L0 L1L1 F CB A E D L0L0 L1L1 F

BFS Example (cont.) CB A E D L0L0 L1L1 F CB A E D L0L0 L1L1 F L2L2 CB A E D L0L0 L1L1 F L2L2 CB A E D L0L0 L1L1 F L2L2

CB A E D L0L0 L1L1 F L2L2 CB A E D L0L0 L1L1 F L2L2 CB A E D L0L0 L1L1 F L2L2

Properties of BFS Also visits all the vertices and edges in a connected component Discovery edges create spanning tree of the component For each vertex v in L i Path from s to v in spanning tree has exactly i edges No paths from s to v in G has fewer than i edges CB A E D L0L0 L1L1 F L2L2

DFS vs. BFS Back edge (v,w) w is ancestor of v in tree of discovery edges Cross edge (v,w) v in same or previous level as w in tree of discovery edges CB A E D L0L0 L1L1 F L2L2 CB A E D F DFSBFS

For Next Lecture Review all our work with Graphs so far Come ready with questions you have Have fun & interesting problems to work on