0% found this document useful (0 votes)
24 views

State Space Search:: Breadth First and Depth First

1. Breadth-first search explores nodes in levels, exploring nearest nodes first before further ones, while depth-first search explores along each path as deep as possible before backtracking. 2. Both can be used to search state spaces to solve problems by reaching a goal state from a starting point using a successor function, with breadth-first prioritizing exploring nearby nodes and depth-first prioritizing complete paths. 3. Breadth-first search uses a queue while depth-first search uses a stack, with the key difference being whether children are explored before or after siblings.

Uploaded by

vibhusha
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

State Space Search:: Breadth First and Depth First

1. Breadth-first search explores nodes in levels, exploring nearest nodes first before further ones, while depth-first search explores along each path as deep as possible before backtracking. 2. Both can be used to search state spaces to solve problems by reaching a goal state from a starting point using a successor function, with breadth-first prioritizing exploring nearby nodes and depth-first prioritizing complete paths. 3. Breadth-first search uses a queue while depth-first search uses a stack, with the key difference being whether children are explored before or after siblings.

Uploaded by

vibhusha
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

State Space Search:

Breadth First and Depth First


Motivations

• Many problems can be viewed as reaching a


goal state from a given starting point, e.g., the
farmer-wolf-goat-cabbage problem.
• Often there is an underlying state space
successor function to proceed from one state
to the next.
• Search strategies are important methods to
explore such a space to obtain the goal state.
Objectives

1. Top down search


2. Bottom up search
3. Breadth first search
4. Depth first search
5. Compare breadth first and depth first
State space for tic-tac-toe game

• Represent a problem
as a state space
• Nodes represent
discrete states, e.g.,
configuration of game
board.
• Arcs (links, edges)
represent transition
between states e.g.,
move in a game.
• Analyze the structure
and complexity of
problem and search
procedures using
graph theory.
Am I a descendant of Thomas Jefferson?
• The third President of the United States (1801–1809)
• Assume no complete record of Jefferson’s family tree.
• Need to do some research.
• 2 search strategies
– top-down: search from Jefferson to I
– bottom-up: search from I to Jefferson
• Assume 10 generations has past since Jefferson
– Depth of family tree is 10
• top-down
– Assume average 3 children per family
– branch factor is 3
– How many nodes to search?
– 3 + 32 + 33+ … + 310
• bottom-up
– For each child, search 2 parents
– branch factor is 2
– How many nodes to search?
– 2 + 22 + 23+ … + 210
Breadth-first searching

• A breadth-first search (BFS)


A explores nodes nearest the
root before exploring nodes
B C
further away
• For example, after
searching A, then B, then C,
D E F G
the search proceeds with D,
E, F, G
H I J K • Node are explored in the
order A B C D E F G H I J K L
L M N O P Q MNOPQ
• J will be found before N
Breadth-first search algorithm

Nodes are lining up to be visited in open.


closed keeps track of all the nodes visited already.
A trace of
breadth-first algorithm

B is not the goal.


Put his children onto the queue.
| Put him in closed. He is done.
| |
Items between red
| | bars are siblings.
| | |
| | |
| | | |
goal is reached or open is empty.
Progress at iteration 6

open contains the nodes


whose children have not been
looked at yet. The queue is
also called the frontier of the
search.
closed contains the nodes that
have been visited, i.e., nodes
that have been opened or
expanded.

|
| |
| |
| | |
| | |
| | | |
Breadth-first searching summary

B C

D E F G

H I J K

L M N O P Q
Depth-first searching
• A depth-first search (DFS)
explores a path all the way
to a leaf before
A backtracking and exploring
another path
B C • For example, after
searching A, then B, then
D, the search backtracks
D E F G
and tries another path from
B
H I J K • Node are explored in the
order A B D E H L M N I
L M N O P Q OPCFGJKQ
• N will be found before J
The depth-first search algorithm

This is the only difference between


depth-first and breadth-first.
A trace of
depth-first algorithm

top of stack
Snap shot at iteration 6
frontier

visited
Recursive depth-first search algorithm

• DFS(node v) {
visit(v)
for each child w of v, DFS(w)
}

• Recursion uses a stack to store data for previous


calls. The children nodes (w’s)are placed on the
undeclared (implicit) stack.
• Breadth first uses a queue instead of a stack, no
recursion.
• At any given time, the top of the stack contains only
the node on a path from the root to a goal.
• The stack only needs to be large enough to hold the
deepest search path.
• When a goal node is found, the path can be extracted
from the stack as the recursion unwinds.
Search sequences of depth-first and breadth-first

Breadth first: A, B, C, …

Depth first: 1, 2, 3, …
Comparing the ordering of search sequences
• Determine the order of nodes (states) to be examined
• Breadth-first search
– When a state is examined, all of its children are
examined, one after another
– Explore the search space in a level-by-level
fashion
• Depth-first search
– When a state is examined, all of its children and
their descendants are examined before any of
its siblings
– Go deeper into the search space where
possible
Breadth-first search of the 8-puzzle

   
Cannot move
blank downward


Depth-first search of 8-puzzle with a depth bound of 5

Breadth-first
took
46 nodes.
Summary

• Graph representation
– Nodes are problem solution states
– Arcs are steps in problem solving
• State Space Search
– Find a solution path from start state to goal
state.
– Determine complexity of problem
– Many problems (TSP) have exponential
complexity, impossible to search exhaustively
– Strategies to search large space need heuristic
to reduce space and time complexity

You might also like