State Space Search:: Breadth First and Depth First
State Space Search:: Breadth First and Depth First
• 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
|
| |
| |
| | |
| | |
| | | |
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
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)
}
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