Jecho and Donatus Depth First and Breadth First Search.

Slides:



Advertisements
Similar presentations
Uninformed search strategies
Advertisements

Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
CS203 Lecture 15.
Introduction to Algorithms Lecture 12 Prof. Constantinos Daskalakis CLRS
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 14, 2012.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Review Binary Search Trees Operations on Binary Search Tree
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
CSE 2331/5331 Topic 11: Basic Graph Alg. Representations Undirected graph Directed graph Topological sort.
Solving Problems by Searching Currently at Chapter 3 in the book Will finish today/Monday, Chapter 4 next.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
Breadth-First and Depth-First Search
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Artificial Intelligence (CS 461D)
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
UNINFORMED SEARCH Problem - solving agents Example : Romania  On holiday in Romania ; currently in Arad.  Flight leaves tomorrow from Bucharest.
Advanced Data Structures
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Tyler Robison Summer
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Dan Grossman Spring 2010.
UnInformed Search What to do when you don’t know anything.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Alyce Brady CS 510: Computer Algorithms Breadth-First Graph Traversal Algorithm.
Using Search in Problem Solving
COMP171 Depth-First Search.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
Alyce Brady CS 510: Computer Algorithms Depth-First Graph Traversal Algorithm.
Using Search in Problem Solving
Breadth First Search (BFS) Part 2 COMP171. Graph / Slide 2 Shortest Path Recording * BFS we saw only tells us whether a path exists from source s, to.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Search  Exhaustive/Blind Search Methods Depth First Search Breadth First Search  Heuristic Methods Hill Climbing Beam Search Best First Search…
Problem-solving agents
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
CS261 Data Structures DFS and BFS – Edge List Representation.
3.0 State Space Representation of Problems 3.1 Graphs 3.2 Formulating Search Problems 3.3 The 8-Puzzle as an example 3.4 State Space Representation using.
Busby, Dodge, Fleming, and Negrusa. Backtracking Algorithm Is used to solve problems for which a sequence of objects is to be selected from a set such.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Search Related Algorithms. Graph Code Adjacency List Representation:
Tree Searching Breadth First Search Dept First Search.
WAES 3308 Numerical Methods for AI
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning.
10 Copyright © William C. Cheng Data Structures - CSCI 102 Graph Terminology A graph consists of a set of Vertices and a set of Edges C A B D a c b d e.
Lecture 3: Uninformed Search
Problem solving by search Department of Computer Science & Engineering Indian Institute of Technology Kharagpur.
Basic Problem Solving Search strategy  Problem can be solved by searching for a solution. An attempt is to transform initial state of a problem into some.
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
CPSC 322, Lecture 6Slide 1 Uniformed Search (cont.) Computer Science cpsc322, Lecture 6 (Textbook finish 3.5) Sept, 17, 2012.
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.
Union By Rank Ackermann’s Function Graph Algorithms Rajee S Ramanikanthan Kavya Reddy Musani.
Graphs and Paths : Chapter 15 Saurav Karmakar
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
Graph Representations And Traversals. Graphs Graph : – Set of Vertices (Nodes) – Set of Edges connecting vertices (u, v) : edge connecting Origin: u Destination:
Solving problems by searching Uninformed search algorithms Discussion Class CS 171 Friday, October, 2nd (Please read lecture topic material before and.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
CSE 373 Topological Sort Graph Traversals
CSE 2331/5331 Topic 9: Basic Graph Alg.
CS120 Graphs.
Search Related Algorithms
Graphs.
Depth-First Searches Introduction to AI.
Graphs Part 2 Adjacency Matrix
COMP171 Depth-First Search.
UNINFORMED SEARCH -BFS -DFS -DFIS - Bidirectional
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -
Depth-First Searches.
Presentation transcript:

Jecho and Donatus Depth First and Breadth First Search

Presentation Outline Overview Illustration Pseudocode Summary

Overview Searching in graphs is done to find which vertices can be reached from a starting vertex by following a path along the edges. Depth-first search and Breadth-first search are two searching algorithms that operate on graphs. Both of these functions start at a vertex and visit every vertex between it and a destination vertex. The algorithms find any paths that exist between two vertices. If a path exists, the path data, which is the order of the edges needed to get from start to finish, is built and stored for some meaningful purpose. Allen Sherrod. Data Structures and Algorithms for Game Developers -chapt 4, 2007

Finding a path from the vertex Los Angeles to new York

Depth-First Search Pseudocode Depth-First Search The depth-first search is an algorithm that uses a stack data structure to start at a starting vertex and move until it reaches the destination, assuming it can be reached from that vertex. The steps of the algorithm are: i. Declare two empty lists: Open and Closed. ii. Add Start node to our Open list. iii. While our Open list is not empty, loop the following: a. Remove the first node from our Open List. b. Check to see if the removed node is our destination. i. If the removed node is our destination, break out of the loop, add the node to our Closed list, and return the value of our Closed list. ii. If the removed node is not our destination, continue the loop (go to Step c). c. Extract the neighbors of our above removed node. d. Add the neighbors to the beginning of our Open list, and add the removed node to our Closed list. Continue looping.

Fig 1.0 Depth-First Search Allen Sherrod. Data Structures and Algorithms for Game Developers -chapt 11, 2007

Illustration – Depth First Search Open List: A Closed List: Open List: B, C Closed List: A Open List: D, E, C Closed List: A, B Step 0 Step 1 Step 2 Kirupa.com - Depth First and Bread First Search

Illustration – Depth First Search Open List: G, C Closed List: A, B, D, E, F Open List: F,G, C Closed List: A, B, D, E Open List: E, C Closed List: A, B, D Step 3 Step 4 Step 5 Kirupa.com - Depth First and Breadth First Search

Breadth-First Search Pseudocode In the breath-first search all adjacent vertices to the current vertex are checked before the algorithm moves forward, and it uses a queue instead of a stack. i. Declare two empty lists: Open and Closed. ii. Add Start node to our Open list. iii. While our Open list is not empty, loop the following: a. Remove the first node from our Open List. b. Check to see if the removed node is our destination. i. If the removed node is our destination, break out of the loop, add the node to our Closed list, and return the value of our Closed list. ii. If the removed node is not our destination, continue the loop (go to Step c). c. Extract the neighbors of our above removed node. d. Add the neighbors to the end of our Open list, and add the removed node to our Closed list. Kiruapa.com - Depth First and Bread First Search, and Allen Sherod - Data Structs and Algorithm Chapt 11, 2007

Breadth-First Search Allen Sherrod. Data Structures and Algorithms for Game Developers -chapt 11, 2007

Illustration – Breadth First Search Open List: A Closed List: Open List: B, C Closed List: A Open List: C, D, E Closed List: A, B Step 0 Step 1 Step 2 Kiruapa.com - Depth First and Bread First Search, and Allen Sherod - Data Structs and Algorithm Chapt 11, 2007

Illustration – Breadth First Search Open List: E Closed List: A, B, C, D Open List: D, E Closed List: A, B, C Open List: Closed List: A, B, C, D, E Step 3 Step 4 Step 5 Kiruapa.com - Depth First and Bread First Search

DFS Features Worst case performance O( | V | + | E | ) for explicit graphs traversed without repetition, O(b d ) for implicit graphs with branching factor b searched to depth d. Worst case space complexity O( | V | ) if entire graph is traversed without repetition, O(longest path length searched) for implicit graphs without elimination of duplicate nodes Wikipedia/DFS

BFS Features Worst case performance O( | V | + | E | ) = O(b d ) Worst case space complexity O( | V | + | E | ) = O(b d ) B- branching factor, d – graph depth | E | - the set of edges | V | - set of vertices Wikipedia/BFS

Summary Both search methods are considered blind searches (uninformed). They don't know anything about their future or where the target is. The paths the expand are mechanically defined. If a better path exists, they will not take it. If they are taking the wrong path, they won't know it. With large graphs, you may run into cycles or loops Another problem is, what if the left side of your tree has millions of nodes, but your destination is close to the origin on the right side of the tree. Depth first would waste numerous cycles exploring the left side before ever reaching the right side. Breadth first search does not suffer from the same loop problems because it moves horizontally across each depth. Breadth first will always find a solution regardless of what type of search tree you have unless there are infinite nodes. Memory is often a limiting factor. Having millions or billions of nodes, as is the case with searching the web.

Questions? Thanks for your time!