Introduction to Graph Theory Lecture 16: Graph Searching Algorithms.

Slides:



Advertisements
Similar presentations
Depth-First Search1 Part-H2 Depth-First Search DB A C E.
Advertisements

Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Analysis of Algorithms Depth First Search. Graph A representation of set of objects Pairs of objects are connected Interconnected objects are called “vertices.
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22.
Graph Theory, DFS & BFS Kelly Choi What is a graph? A set of vertices and edges –Directed/Undirected –Weighted/Unweighted –Cyclic/Acyclic.
CSE 2331/5331 Topic 11: Basic Graph Alg. Representations Undirected graph Directed graph Topological sort.
CSE 373: Data Structures and Algorithms Lecture 19: Graphs III 1.
Algorithms and Data Structures
Breadth-First and Depth-First Search
Chapter 8, Part I Graph Algorithms.
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.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Data Structures Chapter 12 Graphs Andreas Savva. 2 Definition A graph consists of a set of vertices together with a set of edges. If e = (v,w) is an edge.
CHAPTER 13 Graphs DATA ABSTRACTION AND PROBLEM SOLVING WITH C++ WALLS AND MIRRORS Third Edition Frank M. Carrano Janet J. Prichard Data Abstraction and.
Implementation of Graph Decomposition and Recursive Closures Graph Decomposition and Recursive Closures was published in 2003 by Professor Chen. The project.
Data Structures & Algorithms Graph Search Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Alyce Brady CS 510: Computer Algorithms Breadth-First Graph Traversal Algorithm.
1 Data Structures and Algorithms Graphs I: Representation and Search Gal A. Kaminka Computer Science Department.
COMP171 Depth-First Search.
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.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Alyce Brady CS 510: Computer Algorithms Depth-First Graph Traversal Algorithm.
Graph Traversals CSC 172 SPRING 2004 LECTURE 21. Announcements  Project 3 is graded  handed back Tuesday  Grad spam, tonight – if you are really anxious.
Depth-first search COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar to pre-order.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
CSC 2300 Data Structures & Algorithms March 30, 2007 Chapter 9. Graph Algorithms.
Depth-First Search Lecture 24 COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Graph Search Computing 2 COMP s1. P ROBLEMS ON G RAPHS What kinds of problems do we want to solve on/via graphs? Is there a simple path from A to.
ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.
CSC 331: Algorithm Analysis Decompositions of Graphs.
CSC 213 – Large Scale Programming. Today’s Goals  Make Britney sad through my color choices  Revisit issue of graph terminology and usage  Subgraphs,
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
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.
1 Chapter 22: Elementary Graph Algorithms II. 2 About this lecture Depth First Search DFS Tree and DFS Forest Properties of DFS Parenthesis theorem (very.
CS 61B Data Structures and Programming Methodology Aug 5, 2008 David Sun.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
Depth-First Search Lecture 21: Graph Traversals
Introduction to Graph Theory Lecture 17: Graph Searching Algorithms.
Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications.
Graph and Digraph Sung Yong Shin TC Lab. CS Dept., KAIST.
Graph Connectivity This discussion concerns connected components of a graph. Previously, we discussed depth-first search (DFS) as a means of determining.
February 11, 2016Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 State-Space Graphs There are various methods for searching.
Graphs and Paths : Chapter 15 Saurav Karmakar
Now, Chapter 5: Decrease and Conquer Reduce problem instance to smaller instance of the same problem and extend solution Solve smaller instance Extend.
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.
Lecture 7 Graph Traversal
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Review Graph Directed Graph Undirected Graph Sub-Graph Spanning Sub-Graph Degree of a Vertex Weighted Graph Elementary and Simple Path Link List Representation.
CSC 172 DATA STRUCTURES.
Graph Algorithms Using Depth First Search
Graphs Part 2 Adjacency Matrix
Lecture 13 CSE 331 Sep 27, 2017.
Depth-First Search Graph Traversals Depth-First Search DFS.
Lecture 6 Graph Traversal
Graph Traversal Lecture 18 CS 2110 — Spring 2019.
Lecture 10 Graph Algorithms
Presentation transcript:

Introduction to Graph Theory Lecture 16: Graph Searching Algorithms

Before getting started … The study materials are from “Algorithms in C” by Robert Sedgewick. The chapter is available online.

Analogy to Exploring a Maze We can view graph searching as exploring a maze  Passages in the maze -> edges in the graph  Intersections in the maze -> vertices in the graph The big question here is --- how to explore the maze systematically to ensure complete coverage.

Exploring a Maze When exploring a maze, we want to  Traverse every part of the maze  Avoid retracing our steps Let’s construct our maze first  Every intersection has a light  A passage has two doors (with windows), one at each end  By opening the door at one end, we can decide if the intersection at the other end is lit

Maze Exploration Strategy The goal is to turn on all the lights, which are initially off, and open all the doors, which are initially off. What should we do to meet this goal? Here we assume that we unroll a ball of string behind us.  So we can always find our way out

Tremaux Exploration At the current intersection:  (i) if no closed door, jump to step (iii). Else open any closed door to any passage and leave it open  (ii) if the intersection at the other end is lit, go to step (i), Else follow that passage and light the intersection at the other end  (iii) if all doors are open, check is at the starting point. If not, go back down the passge that brought you here (rolling the string back up), and go to step (i)

Example So, with the same example, how many different ways are there to traverse the maze?

Depth-First Search Tremaus exploration leads us right to DFS  Visit a vertex, and mark it as having been visited  Recursive visit all the unvisited vertices adjacent to it We can represent the lights in the intersections using a vertex-indexed array  If a vertex is visited, the corresponding entry is marked.

Pseudo-Code (1) With an adjacency matrix

Pseudo-Code (1) With an adjacency-list What is the trace using this adjacency list?

To Handle Disconnected Graph We need a wrapper function which  finds an unmarked vertex (starting vertex), and  triggers the recursive search starting from that vertex

Cost of Running DFS What is the time complexity if using adjacency matrix? What is the time complexity if using adjacency list? Which data structure is a better choice?

DFS Trees The result of DFS search is a set of trees The trees can be represented in a number of ways: Order of visiting Parent link Two links For every edge

Types of Tree Links If traversing an edge from v->w vertices, we can classify the graph edge by looking at the pre and st data structure. Tree edges  Tree link if w is unmarked  A parent link if st[w] is v Back edges  Back link if pre[w]<pre[v]  Down link if pre[w]>pre[v] tree link parent link back link down link

(cont) Each graph edge is represented either as  One tree link and one parent link, OR  One down link and one back link Meaning of the links:  Tree: trigger recursive search (1 st visit)  Parent: do nothing (2 nd visit)  Down: recursive search completed for w (2 nd visit)  Back: recursive search in progress for w (1 st visit)

Some Remarks This representation will provide us a basis for understanding numerous important graph- processing algorithm. DFS corresponds to pre-order tree traversal. It is also possible to do post-ordering, if we assign the number after the recursive call.