Uninformed Search - CMU School of Computer Science

Search
• Examples of Search problems?
• The Oak Tree
• Informed versus Uninformed
Uninformed Search
– Heuristic versus Blind
Day 1 of Search
Russel & Norvig Chap. 3
Material in part from http://www.cs.cmu.edu/~awm/tutorials
A Search Problem
Example
a
GOAL
c
b
e
f
d
START
h
p
1
5
3
8
2
4
7
6
1
2
3
4
5
6
7
8
r
q
START
GOAL
• Find a path from START to GOAL
• Find the minimum number of transitions
Example: Robot Navigation
Example
1 5 3
8 2 4
7 6
1 2
3 4 5
6 7 8
START
GOAL
• State: Configuration of puzzle
• Transitions: Up to 4 possible moves (up, down,
left, right)
• Solvable in 22 steps (average)
• But: 1.8 105 states (1.3 1012 states for the 15puzzle)
Cannot represent set of states explicitly
States =
positions in the map
Transitions =
allowed motions
x
N
GOAL
E
W
X
START
S
Navigation: Going from point START to
point GOAL given a (deterministic) map
1
Example Solution: Brushfire…
Other Real-Life Examples
Protein design
http://www.blueprint.org/proteinfolding/trades/trades_problem.html
x
GOAL
Scheduling/Manufacturing
http://www.ozone.ri.cmu.edu/projects/dms/dmsmain.html
X
Route planning
START
Robot navigation
http://www.frc.ri.cmu.edu/projects/mars/dstar.html
Don’t necessarily know explicitly the
structure of a search problem
Scheduling/Science
http://www.ozone.ri.cmu.edu/projects/hsts/hstsmain.html
Other Real-Life Examples
Protein design
http://www.blueprint.org/proteinfolding/trades/trades_problem.html
Scheduling/Manufacturing
http://www.ozone.ri.cmu.edu/projects/dms/dmsmain.html
Route planning
Robot navigation
http://www.frc.ri.cmu.edu/projects/mars/dstar.html
Don’t have a clue when you’re doing well
versus poorly!
Scheduling/Science
http://www.ozone.ri.cmu.edu/projects/hsts/hstsmain.html
10cm resolution
4km2 = 4 108 states
What we are not addressing (yet)
• Uncertainty/Chance
State and transitions are known and deterministic
• Game against adversary
• Multiple agents/Cooperation
• Continuous state space
For now, the set of states is discrete
Overview
• Definition and formulation
• Optimality, Completeness, and Complexity
• Uninformed Search
–
–
–
–
Breadth First Search
Search Trees
Depth First Search
Iterative Deepening
• Informed Search
– Best First Greedy Search
– Heuristic Search, A*
2
A Search Problem:
Square World
Formulation
•
•
•
•
Q: Finite set of states
S ⊆ Q: Non-empty set of start states
G ⊆ Q: Non-empty set of goal states
succs: function Q
P(Q)
•
cost: function QxQ
•
Problem: Find a sequence {s1,…,sK} such that:
succs(s) = Set of states that can be reached from s in one step
Positive Numbers
cost(s,s’) = Cost of taking a one-step transition from state s to state s’
1. s1 ∈S
2. sK∈G
3. si+1 ∈ succs(si)
Σ cost(si, si+1) is the smallest among all possible
sequences (desirable but optional)
4.
Example
What about actions?
•
•
•
•
Q: Finite set of states
S ⊆ Q: Non-empty set of start states
G ⊆ Q: Non-empty set of goal states
succs: function Q
P(Q)
•
cost: function QxQ
•
Problem: Find a sequence {s1,…,sK} such that:
succs(s) = Set of states that can be reached from s in one step
Positive Numbers
cost(s,s’) = Cost of taking a one-step transition from state s to state s’
•
•
•
•
Actions define transitions from states to states.
Example: Square World
Q = {AA, AB, AC, AD, AI, BB, BC, BD, BI, …}
S = {AB} G = {DD}
succs(AA) = {AI,BA}
cost(s,s’) = 1 for each action (transition)
Desirable Properties
a
a
cc
b
b
e
e
d
d
START
START
Breadth-First Search
GOAL
GOAL
p
p
c
b
ff
h
h
GOAL
a
e
f
d
START
h
rr
q
q
• Completeness: An algorithm is complete if it is
guaranteed to find a path if one exists
• Optimality: The total cost of the path is the lowest
among all possible paths from start to goal
• Time Complexity
• Space Complexity
p
r
q
• Label all states that are 0 steps from S
Call that set Vo
3
Breadth-First Search
0 steps
GOAL
a
1 step
c
b
0 steps
1 step
2 steps
c
e
f
d
START
START
h
r
• Label the successors of the states in Vo
that are not yet labelled Set V1 of states
that are 1 step away from the start
Breadth-First Search
GOAL
a
c
0 steps
1 step
2 steps
3 steps
4 steps
Breadth-First Search
GOAL
a
c
b
e
f
d
f
d
START
h
h
r
p
q
• Label the successors of the states in V1
that are not yet labelled Set V2 of states
that are 1 step away from the start
e
START
r
p
q
b
f
d
h
p
GOAL
a
b
e
0 steps
1 step
2 steps
3 steps
Breadth-First Search
r
p
q
q
• Label the successors of the states in V2
that are not yet labelled Set V3 of states
that are 1 step away from the start
• Stop when goal is reached in the current
goal can be reached in 4
expansion set
steps
Recovering the Path
Using Backpointers
a
c
b
e
f
d
START
c
b
e
h
GOAL
a
GOAL
f
d
START
h
r
p
q
• Record the predecessor state when labeling a new state
• When I labeled GOAL, I was expanding the neighbors of
f so therefore f is the predecessor of GOAL
• When I labeled f, I was expanding the neighbors of r so
therefore r is the predecessor of f
• Final solution: {START, e, r, f, GOAL}
p
r
q
• A backpointer previous(s) points to the node that
stored the state that was expanded to label s
• The path is recovered by following the
backpointers starting at the goal state
4
Example: Robot Navigation
Breadth First Search
V0
S (the set of start states)
previous(START) := NULL
k
0
States =
positions in the map
Transitions =
allowed motions
x
while (no goal state is in Vk and Vk is not empty) do
Vk+1
empty set
For each state s in Vk
N
GOAL
For each state s’ in succs(s)
k
X
START
If s’ has not already been labeled
Set previous(s’)
s
Add s’ into Vk+1
E
W
S
Navigation: Going from point START to
point GOAL given a (deterministic) map
k+1
if Vk is empty signal FAILURE
else build the solution path thus:
Define Sk = GOAL, and forall i <= k, define Si-1 = previous(Si)
Return path = {S1,.., Sk}
Complexity
Properties
• BFS can handle multiple start and goal
states *what does multiple start mean?*
• Can work either by searching forward from
the start or backward for the goal
(forward/backward chaining)
• (Which way is better?)
• Guaranteed to find the lowest-cost path in
terms of number of transitions??
• N = Total number of states
• B = Average number of successors (branching factor)
• L = Length from start to goal with smallest number of steps
Algorithm
BFS
Complete Optimal
Time
Space
Breadth First
Search
See maze example
Complexity
• N = Total number of states
• B = Average number of successors (branching factor)
• L = Length from start to goal with smallest number of steps
Algorithm
BFS
Breadth First
Search
Complete Optimal
Y
Y, If all
trans. have
same cost
Time
Space
O(min(N,BL)) O(min(N,BL))
Bidirectional Search
• BFS search simultaneously forward from
START and backward from GOAL
• When do the two search meet?
• What stopping criterion should be used?
• Under what condition is it optimal?
V3
START
V1
V2
V’3
V’2
V’1
GOAL
5
Complexity
Complexity
• N = Total number of states
• B = Average number of successors (branching factor)
• L = Length for start to goal with smallest number of steps
• N = Total number of states
• B = Average number of successors (branching factor)
• L = Length for start to goal with smallest number of steps
Algorithm
Complete Optimal
Time
Space
Algorithm
BFS
Breadth First
Search
BFS
Breadth First
Search
BIBFS
Bi-directional
Breadth First
Search
BIBFS
Bi-directional
Breadth First
Search
Major savings when bidirectional search is possible because
2BL/2 << BL
B = 10, L = 6
Complete Optimal
Y
B = 10, L = 6
BIBFS
Complete Optimal
Breadth First
Search
Y
Bi-directional
Breadth First
Search
Y
Space
O(min(N,BL))
O(min(N,BL))
22,200 states generated vs. ~107
Complexity
Algorithm
Time
Major savings when bidirectional search is possible because
2BL/2 << BL
22,200 states generated vs. ~107
Complexity
• N = Total number of states
• B = Average number of successors (branching factor)
• L = Length for start to goal with smallest number of steps
BFS
Y, if all
trans. have
same cost
• A note about island-driven search in general:
– What happens to complexity if you have L islands enroute to the
goal?
Time
Space
Y, if all
trans. have
same cost
O(min(N,BL))
O(min(N,BL))
Y, If all
trans. have
same cost
O(min(N,2BL/2))
Time
Space
BFS
Algorithm
Breadth First
Search
Y
Y, if all
trans. have
same cost
O(min(N,BL))
O(min(N,BL))
BIBFS
Bi-directional
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,2BL/2)) O(min(N,2BL/2))
O(min(N,2BL/2))
Complete Optimal
Major savings when bidirectional search is possible because
2BL/2 << BL
B = 10, L = 6
22,200 states generated vs. ~107
Counting Transition Costs Instead of Transitions
Counting Transition Costs Instead of Transitions
a
2
a
2
b
2
8
1
5
c
2
1
9
START
1
p
4
15
q
r
3
2
p
1
5
f
9
h
5
4
15
GOAL
e
4
1
5
c
9
START
9
5
d
f
h
4
8
1
3
5
e
d
3
b
GOAL
2
q
r
3
• BFS finds the shortest path in number of steps but
does not take into account transition costs
• Simple modification finds the least cost path
• New field: At iteration k, g(s) = least cost path to s in k
or fewer steps
6
Priority Queue
Uniform Cost Search
• Strategy to select state to expand next
• Use the state with the smallest value of g()
so far
• Use priority queue for efficient access to
minimum g at every iteration
• Priority queue = data structure in which data of
the form (item, value) can be inserted and the
item of minimum value can be retrieved
efficiently
• Operations:
– Init (PQ): Initialize empty queue
– Insert (PQ, item, value): Insert a pair in the queue
– Pop (PQ): Returns the pair with the minimum value
• In our case:
– item = state value = current cost g()
Complexity: O(log(number of pairs in PQ)) for
insertion and pop operations
very efficient
http://www.leekillough.com/heaps/ Knuth&Sedwick ….
Uniform Cost Search
•
•
•
a
2
PQ = Current set of evaluated states
Value (priority) of state = g(s) = current cost
of path to s
Basic iteration:
1. Pop the state s with the lowest path cost from PQ
2. Evaluate the path cost to all the successors of s
3. Add the successors of s to PQ
b
2
c
8
1
2
1
9
START
a
b
2
3
PQ = {(START,0)}
8
1
c
2
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
1
9
START
1
p
PQ = {(p,1) (d,3) (e,9)}
q
8
1
r
3
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
c
2
1
5
4
15
PQ = {(d,3) (e,9) (q,16)}
f
9
h
4
p
5
e
9
1
GOAL
5
d
3
5
4
15
2
START
h
4
b
f
9
a
2
5
e
d
3
GOAL
5
r
q
15
We add the successors of s that have
not yet been visited and we update the
cost of those currently in the queue
2
5
4
p
f
9
h
4
1
5
e
d
3
GOAL
5
q
r
3
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
7
a
2
b
2
8
1
5
c
2
1
9
START
h
4
1
p
a
b
2
1
9
h
4
1
p
PQ = {(e,5) (a,6) (c,11) (q,16)}
a
2
b
8
1
c
2
d
3
1
9
START
h
4
1
p
5
4
15
r
q
3
PQ = {(h,6) (c,11) (r,14) (q,16)} 1.
h
Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
5
r
q
15
f
9
3
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
a
2
b
f
9
1
PQ = {(a,6) (h,6) (c,11) (r,14) (q,16)}
5
e
5
e
4
p
GOAL
5
2
9
1
GOAL
5
4
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
2
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
d
3
5
f
1 9
Important:
h We realized that
going to e through d 5is
cheaper
than going
4
r to e
directly
the value of e is
q
3
updated from 9 to 5 and it
moves up in PQ
c
8
1
GOAL
e
2
START
r
q
15
b
3
5
4
a
2
f
9
15
2
PQ = {(b,4) (e,5) (c,11) (q,16)}
5
e
d
3
START
p
GOAL
5
c
4
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
2
8
1
9
3
PQ = {(b,4) (e,5) (c,11) (q,16)}
2
d
1
5
c
8
START
r
q
15
2
1
3
5
4
b
f
9
a
2
5
e
d
3
GOAL
2
8
1
c
2
1
9
START
p
5
4
15
PQ = {(q,10) (c,11) (r,14)}
f
9
h
4
1
5
e
d
3
GOAL
5
q
r
3
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
8
a
2
b
2
c
8
1
2
d
3
1
r
3
Important: We realized that
Pop the state s with the
(r,14)}going to1.q lowest
through
h is
path cost from PQ
cheaper than
going through
2. Evaluate
the path cost to
of s
p
the valueallofthe
q successors
is updated
Add the successors of s to
from 16 to3.10PQ
and it moves
up in PQ
PQ = {(q,10) (c,11)
a
2
b
2
c
2
d
h
4
1
a
2
b
2
8
1
c
2
1
9
START
1
p
15
q
h
5
4
15
f
9
q
r
3
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
Example: Robot Navigation
States =
positions in the map
Transitions =
allowed motions
5
4
1
f
9
h
4
p
5
e
d
5
e
d
3
2
PQ = {(GOAL,23)}
GOAL
5
c
9
1
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
PQ = {(f,18)}
8
GOAL
5
4
3
PQ = {(r,13)}
1. Pop the state s with the
lowest path cost from PQ
2. Evaluate the path cost to
all the successors of s
3. Add the successors of s to
PQ
START
r
q
15
3
2
1
3
5
4
p
f
9
1
9
START
b
5
r
q
15
a
2
5
e
h
4
p
f
9
1
PQ = {(c,11) (r,13)}
GOAL
5
8
1
3
1
5
e
4
q
15
2
9
4
p
c
d
5
GOAL
5
8
START
h
4
2
1
3
f
9
1
9
START
b
5
e
a
2
GOAL
5
x
GOAL
r
N
Cost = sqrt(2)
3
E
W
Final path: {START, d, e, h, q, r, f, GOAL}
Cost = 1
X
• This path is optimal in total cost even though it has more
transitions than the one found by BFS
• What should be the stopping condition?
• Under what conditions is UCS complete/optimal?
START
S
Navigation: Going from point START to
point GOAL given a (deterministic) map
9
Complexity
•
•
•
•
Complexity
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
Q = Average size of the priority queue
Algorithm
BFS
Breadth First
Search
BIBFS
Bi-directional
Breadth First
Search
UCS
Uniform Cost
Search
Complete Optimal
Time
•
•
•
•
•
Space
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Time
Space
BFS
Algorithm
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,BL))
O(min(N,BL))
BIBFS
Bi-directional
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,2BL/2))
O(min(N,2BL/2))
UCS
Uniform Cost
Search
Complexity
•
•
•
•
•
•
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
ε = average cost per link?
Time
Space
BFS
Algorithm
Breadth First
Search
Complete Optimal
Y
Y, If all
trans. have
same cost
O(min(N,BL))
O(min(N,BL))
BIBFS
Bi-directional
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,2BL/2))
O(min(N,2BL/2))
UCS
Uniform Cost
Search
Y, If cost >
ε>0
Y, If cost > 0
O(log(Q)*min(N,BC/ε))
O(min(N,BC/ε))
Philosophical Limitation
• We cannot shoot for perfection, we want
good enough…
Complete Optimal
Limitations of BFS
• Memory usage is O(BL) in general
• Limitation in many problems in which the
states cannot be enumerated or stored
explicitly, e.g., large branching factor
• Alternative: Find a search strategy that
requires little storage for use in large
problems
“left first:”
Depth First Search
START
START d
START d b
START d b a
START d c
START d c a
START
START d e
START d e r
START d e r f
START d e r f c
START d e r f c a
START d e r f GOAL
a
GOAL
c
b
e
f
d
h
p
q
r
• General idea:
– Expand the most recently expanded node if it has
successors
– Otherwise backup to the previous node on the current path
10
Depth First Search
DFS Implementation
a
START
START d
c
START d b
b
e
START d b a
d
May explore the
START d c
same state over
START d c a START
h
again. Potential 4
START d e
problem?
START d e r
p
q
START d e r f
START d e r f c
START d e r f c a
Memory usage never
exceeds maximum length of
START d e r f GOAL
DFS (s)
if s = GOAL
return SUCCESS
else
For all s’ in succs(s)
DFS (s’)
In a recursive
implementation, the program
stack keeps track of the
states in the current path
return FAILURE
s is current state being expanded,
starting with START
DFS:
START
d
b c
e
e
a ar
f
h
r
hq
f
p
d
b c
a ar
q
p q e GOAL q
c GOAL q
f
a
e
e
h
p
r
hq
f
p
q
p q e GOAL q
c GOAL q
a
a
a
Root: START state
Children of node containing state s: All states in succs(s)
In the worst case the entire tree is explored
O(BLmax)
Infinite branches if there are loops in the graph!
•
•
•
•
•
•
•
•
•
•
Complexity
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Algorithm
Complete Optimal
Time
r
Complexity
START
p
f
a path through the graph
Search Tree Interpretation
BFS:
GOAL
Space
BFS
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,BL))
O(min(N,BL))
BIBFS
Bi-directional
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,2BL/2))
O(min(N,2BL/2))
UCS
Uniform Cost
Search
Y (if cost >
0)
Y
O(log(Q)*min(N,BC/ε))
O(min(N,BC/ε))
DFS
Depth First
Search
•
•
•
•
•
•
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Algorithm
BFS
Breadth First
Search
BIBFS
Bi-directional
Breadth First
Search
UCS
Uniform Cost
Search
DFS
Depth First
Search
•
•
•
•
•
•
Complete Optimal
Time
Space
Complexity
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Algorithm
Complete Optimal
Time
Space
BFS
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,BL))
O(min(N,BL))
BIBFS
Bi-directional
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,2BL/2))
O(min(N,2BL/2))
UCS
Uniform Cost
Search
Y, If cost >
0
Y, If cost >
0
O(log(Q)*min(N,BC/ε))
O(min(N,BC/ε))
DFS
Depth First
Search
Y
N
O(BLmax)
O(BLmax)
For graphs
without cycles
11
Is this a problem:
Complexity
DFS Limitation 1
• Need to prevent DFS from looping
• Avoid visiting the same states repeatedly
• Lmax = Length of longest path from START to any state
Algorithm
Complete Optimal
Time
Because Bd may be much larger
than the number of states d steps
away from the start
Space
BFS
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,BL))
O(min(N,BL))
BIBFS
Bi-directional
Breadth First
Search
Y
Y, If all
trans. have
same cost
O(min(N,2BL/2))
O(min(N,2BL/2))
UCS
Uniform Cost
Search
Y, If cost >
0
Y, If cost >
0
O(log(Q)*min(N,BC/ε))
O(min(N,BC/ε))
DFS
Depth First
Search
Y
N
O(BLmax)
O(BLmax)
• PC-DFS (Path Checking DFS):
– Don’t use a state that is already in the
current path
• MEMDFS (Memorizing DFS):
– Keep track of all the states expanded so
far. Do not expand any state twice
• Comparison PC-DFS vs. MEMDFS?
For graphs
without cycles
Complexity
•
•
•
•
•
•
Algorithm
BFS
Breadth First
Search
BIBFS
Bi- Direction.
BFS
UCS
Uniform Cost
Search
PCDFS
Path Check
DFS
MEMD
FS
•
•
•
•
•
•
Complete Optimal
Time
Space
Memorizing
DFS
Complexity
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Algorithm
BFS
Complexity
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Breadth First
Search
Complete Optimal
Y
Time
Space
Y, If all trans.
have same cost
O(Min(N,BL))
O(Min(N,BL))
Y, If all trans.
have same cost
O(Min(N,2BL/2))
O(Min(N,2BL/2))
O(log(Q)*Min(N,BC/ ε
))
O(Min(N,BC/ε))
BIBFS
Bi- Direction.
BFS
Y
UCS
Uniform Cost
Search
Y, If cost >
0
Y, If cost > 0
PCDFS
Path Check
DFS
Y
N
O(BLmax)
O(BLmax)
N
O(Min(N,BLmax))
O(Min(N,BLmax))
MEMD
FS
Memorizing
DFS
Y
•
•
•
•
•
•
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Time
Space
BFS
Algorithm
Breadth First
Search
Y
Y, If all trans.
have same cost
O(Min(N,BL))
O(Min(N,BL))
BIBFS
Bi- Direction.
BFS
Y
Y, If all trans.
have same cost
O(Min(N,2BL/2))
O(Min(N,2BL/2))
UCS
Uniform Cost
Search
Y, If cost >
0
O(log(Q)*Min(N,BC/ ε
))
O(Min(N,BC/ε))
PCDFS
Path Check
DFS
MEMD
FS
Memorizing
DFS
Complete Optimal
Y, If cost > 0
DFS Limitation 2
• Need to make DFS optimal
“Depth-Limited
Search”
• IDS (Iterative Deepening Search):
– Run DFS by searching only path of length 1
(DFS stops if length of path is greater than 1)
– If that doesn’t find a solution, try again by
running DFS on paths of length 2 or less
– If that doesn’t find a solution, try again by
running DFS on paths of length 3 or less
– ………..
– Continue until a solution is found
12
Iterative Deepening Search
(DFID)
Iterative Deepening Search
• Sounds horrible: We need to run DFS
many times
• Actually not a problem:
• Memory usage same as DFS
• Computation cost comparable to BFS
even with repeated searches, especially
for large B.
• Example:
O(LB1+(L-1)B2+…+BL) = O(BL)
Nodes generated
at depth 2
Nodes generated
at depth 1
Nodes generated at
depth L
– B=10, L=5
– BFS: 111,111 expansions
– IDS: 123,456 expansions
• Compare BL and BLmax
• Optimal if transition costs are equal
•
•
•
•
•
•
Complexity
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Algorithm
Time
Space
Complexity
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Time
Space
BFS
Breadth First
Search
BFS
Breadth First
Search
Y
Y, If all trans.
have same cost
O(Min(N,BL))
O(Min(N,BL))
BIBFS
Bi- Direction.
BFS
BIBFS
Bi- Direction.
BFS
Y
Y, If all trans.
have same cost
O(Min(N,2BL/2))
O(Min(N,2BL/2))
UCS
Uniform Cost
Search
UCS
Uniform Cost
Search
Y, If cost >
0
Y, If cost > 0
O(log(Q)*Min(N,BC/ ε
))
O(Min(N,BC/ε))
PCDFS
Path Check
DFS
PCDFS
Path Check
DFS
Y
N
O(BLmax)
O(BLmax)
MEMD
FS
Memorizing
DFS
MEMD
FS
Memorizing
DFS
Y
N
O(Min(N,BLmax))
O(Min(N,BLmax))
IDS
Iterative
Deepening
IDS
Iterative
Deepening
•
•
•
•
•
•
Complete Optimal
•
•
•
•
•
•
Complexity
N = Total number of states
B = Average number of successors (branching factor)
L = Length for start to goal with smallest number of steps
C = Cost of optimal path
Q = Average size of the priority queue
Lmax = Length of longest path from START to any state
Time
Space
BFS
Algorithm
Breadth First
Search
Complete Optimal
Y
Y, If all trans.
have same cost
O(Min(N,BL))
O(Min(N,BL))
BIBFS
Bi- Direction.
BFS
Y
Y, If all trans.
have same cost
O(Min(N,2BL/2))
O(Min(N,2BL/2))
UCS
Uniform Cost
Search
Y, If cost >
0
O(log(Q)*Min(N,BC/ ε
))
O(Min(N,BC/ε))
Y, If cost > 0
PCDFS
Path Check
DFS
Y
N
O(BLmax)
O(BLmax)
MEMD
FS
Memorizing
DFS
Y
N
O(Min(N,BLmax))
O(Min(N,BLmax))
IDS
Iterative
Deepening
Y
Y, If all trans.
have same cost
O(BL)
O(BL)
Algorithm
Complete Optimal
Summary
• Basic search techniques: BFS, UCS,
PCDFS, MEMDFS, DFID
• Property of search algorithms:
Completeness, optimality, time and space
complexity
• Iterative deepening and bidirectional
search ideas
• Trade-offs between the different
techniques and when they might be used
13
Some Challenges
• Driving directions
• Robot navigation in Wean Hall
• Adversarial games
– Tic Tac Toe
– Chess
14