Simple Search Algorithm

Slides:



Advertisements
Similar presentations
Heuristic Search techniques
Advertisements

Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8.
CS 267: Automated Verification Lecture 10: Nested Depth First Search, Counter- Example Generation Revisited, Bit-State Hashing, On-The-Fly Model Checking.
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.
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.
SICP Search Algorithms Why search Data structures that support search Breadth first vs. depth first.
COSC 2007 Data Structures II
Brian Williams, Fall 041 Analysis of Uninformed Search Methods Brian C. Williams Sep 21 st, 2004 Slides adapted from: Tomas Lozano Perez,
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
CSC 172 DATA STRUCTURES.
Graphs A New Data Structure
Lecture 3: Uninformed Search
Graphs Chapter 15 introduces graphs which are probably the most general and commonly-used data structure. This lecture introduces heaps, which are used.
Thinking about Algorithms Abstractly
A vertex u is reachable from vertex v iff there is a path from v to u.
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,
Motivation and Background
Lecture 12 Graph Algorithms
Uninformed Search Chapter 3.4.
Ellen Walker CPSC 201 Data Structures Hiram College
Uninformed Search Introduction to Artificial Intelligence
Prof. Dechter ICS 270A Winter 2003
Spanning Trees Longin Jan Latecki Temple University based on slides by
CSE 421: Introduction to Algorithms
Data Structures – Stacks and Queus
Graphs Chapter 13.
What to do when you don’t know anything know nothing
EA C461 – Artificial Intelligence
Artificial Intelligence
Breadth-First Searches
Lectures on Graph Algorithms: searching, testing and sorting
Graphs.
Depth-First Searches Introduction to AI.
Graphs Part 2 Adjacency Matrix
Tree Searching.
Spanning Trees Longin Jan Latecki Temple University based on slides by
Richard Anderson Autumn 2016 Lecture 5
Subgraphs, Connected Components, Spanning Trees
Artificial Intelligence
COMP171 Depth-First Search.
CSE 373: Data Structures and Algorithms
Uninformed search Lirong Xia. Uninformed search Lirong Xia.
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
EMIS 8374 Search Algorithms Updated 9 February 2004
Depth-First Search CSE 2011 Winter April 2019.
A vertex u is reachable from vertex v iff there is a path from v to u.
Tree Searching.
Graphs.
Tree Searching.
Tree Searching.
Spanning Trees Longin Jan Latecki Temple University based on slides by
Graphs.
Graphs.
UNINFORMED SEARCH -BFS -DFS -DFIS - Bidirectional
State-Space Searches.
Kruskal’s Algorithm AQR.
State-Space Searches.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Graphs.
CMSC 471 Fall 2011 Class #4 Tue 9/13/11 Uninformed Search
Algorithm Course Dr. Aref Rashad
David Kauchak CS51A – Spring 2019
Graph Search in C++ Andrew Lindsay.
Lecture 11 Graph Algorithms
State-Space Searches.
EMIS 8374 Search Algorithms Updated 12 February 2008
Depth-First Searches.
Presentation transcript:

Simple Search Algorithm Let S be the start state Initialize Q with the start node Q=(S) as only entry; set Visited = (S) If Q is empty, fail. Else pick node X from Q If X is a goal, return X, we’ve reached the goal (Otherwise) Remove X from Q Find all the children of node X not in Visited Add these to Q; Add Children of X to Visited Go to Step 2 The search strategies we will look at are all instances of a common search algorithm, which is shown here. The basic idea is to keep a list (Q) of nodes (that is, partial paths), then to pick one such node from Q, see if it reaches the goal and otherwise extend that path to its neighbors and add them back to Q. Except for details, that's all there is to it. Note, by the way, that we are keeping track of the states we have reached (visited) and not entering them in Q more than once. This will certainly avoid us ever looping, no matter how the underlying graph is connected, since we can only ever reach a state once. We will explore the impact of this decision later.

DFS: Example Q Visited 1 2 3 4 5 S A B C D E F G H We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

DFS: Example Q Visited 1 S 2 3 4 5 S A B C D E F G H We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

DFS: Example Q Visited 1 S 2 A,B S,A,B 3 4 5 S A B C D E F G H We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

DFS: Example Q Visited 1 S 2 A,B S,A,B 3 C,D,B S,A,B,C,D 4 5 S A B C D G H Q Visited 1 S 2 A,B S,A,B 3 C,D,B S,A,B,C,D 4 5 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

DFS: Example Q Visited 1 S 2 A,B S,A,B 3 C,D,B S,A,B,C,D 4 G,H,D,B 5 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

DFS: Example Q Visited 1 S 2 A,B S,A,B 3 C,D,B S,A,B,C,D 4 G,H,D,B 5 H,D,B We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

DFS: Example S A B C D E F G H Q Visited 1 S 2 A,B S,A,B 3 C,D,B 4 G,H,D,B S,A,B,C,D,G,H 5 H,D,B 6 D,B We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

DFS: Example S A B C D E F G H Q Visited 1 S 2 A,B S,A,B 3 C,D,B 4 G,H,D,B S,A,B,C,D,G,H 5 H,D,B 6 D,B We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example Q Visited 1 2 3 4 5 S A B C D E F G H We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example Q Visited 1 S 2 3 4 5 S A B C D E F G H We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example Q Visited 1 S 2 A,B S,A,B 3 4 5 S A B C D E F G H We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example Q Visited 1 S 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 5 S A B C D G H Q Visited 1 S 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 5 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example Q Visited 1 S 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 5 S A B C D G H Q Visited 1 S 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 5 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example Q Visited 1 S 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 C,D,E,F G H Q Visited 1 S 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 C,D,E,F S,A,B,C,D,E,F 5 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 C,D,E,F S,A,B,C,D,E,F 5 G H Q Visited 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 C,D,E,F S,A,B,C,D,E,F 5 D,E,F,G,H S,A,B,C,D,E,F,G,H 6 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example 3 B,C,D S,A,B,C,D 4 C,D,E,F S,A,B,C,D,E,F 5 D,E,F,G,H Q Visited 3 B,C,D S,A,B,C,D 4 C,D,E,F S,A,B,C,D,E,F 5 D,E,F,G,H S,A,B,C,D,E,F,G,H 6 E,F,G,H 7 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example Q Visited 4 C,D,E,F S,A,B,C,D,E,F 5 D,E,F,G,H S,A,B,C,D,E,F,G,H 6 E,F,G,H 7 F,G,H 8 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example Q Visited 5 D,E,F,G,H S,A,B,C,D,E,F,G,H 6 E,F,G,H 7 F,G,H 8 G,H 9 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example S A B C D E F G H Q Visited 6 E,F,G,H S,A,B,C,D,E,F,G,H 7 8 G,H 9 H 10 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example S A B C D E F G H Q Visited 6 E,F,G,H S,A,B,C,D,E,F,G,H 7 8 G,H 9 10 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

BFS: Example S A B C D E F G H Q Visited 1 S 2 A,B S,A,B 3 B,C,D S,A,B,C,D 4 C,D,E,F S,A,B,C,D,E,F 5 D,E,F,G,H S,A,B,C,D,E,F,G,H 6 E,F,G,H 7 F,G,H 8 G,H 9 H 10 We start with depth-first search using a Visited list. The table in the center shows the contents of Q and of the Visited list at each time through the loop of the search algorithm. The nodes in Q are indicated by reversed paths, blue is used to indicate newly added nodes (paths). On the right is the graph we are searching and we will label the state of the node that is being extended at each step.

Problem with BFS = (8)10 nodes = (23)10 X 23 = 233 bytes Imagine searching a tree with branching factor 8 and depth 10. Assume a node requires just 8 bytes of storage. The breadth first search might require up to: = (8)10 nodes = (23)10 X 23 = 233 bytes = 8,000 Mbytes = 8 Gbytes Total number of paths in a tree with branching factor b and depth d = b**d (PHW 66) Here it is 8**10 paths. Now if each node requires 8 bytes of storage we require (8**10) * 8 bytes. In general, then, the number of paths is said to explode exponentially as the depth of the search tree increases.

Progressive Deepening A B C D E F G H I J K L M N