Unit 3 - Blind Search
Unit 3 - Blind Search
3. 4 , C h a
– 3 p te r
.6
Blind S earch
1
Search Overview
? Introduction to Search
? Depth-First
? “Iterative Deepening"
? Bi-Directional
? Heuristic Search Techniques
? Stochastic Algorithms
? Game Playing search
? Constraint Satisfaction Problems
2
Generic Search Algorithm
Searchinsert( start, operations, isGoal ): path
L = make-queue( start )
loop
n := pop( L )
if [ isGoal( n )]
return( n )
S := successors( n, operators )
L := insert( S, L )
until L is empty
return( failure )
? Blind Search
? Depth-first search
? Breadth-first search
? Iterative deepening
? …
? Not “guided” by goal
? No matter where the goal is,
these algorithms will do the
same thing.
4
Performance Measures of
S earch Algorithms
? Completeness
Does algorithm always find a sol’n (if ∃)?
? Optimality
Does it always find least cost sol’n?
? Time complexity
How long does it take to find sol’n?
? Space complexity
How much memory is required to find a sol’n?
5
Parameters b
d
7
Breadth-First Search
8
Properties of Breadth-First search
? Complete? Yes (if b is finite)
? Optimal? Yes (if cost = 1 per step)
? Time? O(bd)
? 1 + b + b2 + … + bd/2 = O(bd)
? Space? O(bd)
? keeps every intermediate node in memory
? Optimal
* *: If g( Successor(n) ) ≥ g(n)
Eg, if g(n) = ∑i c(ai)
? Time: O(b )
d is SUM of arc-costs
? Space: O(b )
d
12
To insure optimality
A S
0
1 10
S 5 B 5 G
A B C
1 5 15
5
15 C
G G
11 10
13
Uniform-cost search
? Expand least-cost unexpanded node
? Implementation:
? fringe = queue ordered by path cost
? Equivalent to breadth-first if step costs all equal
? Complete? Yes, if step cost ≥ ε
(in trouble if cost = 0)
? Optimal? Yes
…as nodes expanded in increasing order of cost
? Time? O(b⌈C*/ ε⌉)
where C* = cost of optimal solution
? Space? O(b⌈C*/ ε⌉)
15
Depth-first search
? Expand deepest unexpanded node
? Implementation:
? fringe = LIFO queue, i.e., put successors at front
16
Depth-first Search
17
Properties of Depth-First Search
? Complete? No: fails in infinite-depth spaces, or if loops
? Modify to avoid repeated states along path
? complete in finite spaces
? Optimal? No
… first found ≠? best 20
⋮
? Time? O( bm) :
?terrible if m is much larger than d
?but if solutions are dense, may be much faster than BF
? Space? ( b m)
? d=12 ⇒ 12 kb, not 111 terabytes! 18
BFS/UC vs. DFS
Complete? Optimal? Time Space
BFS/UC YES YES bd bd
DFS finite depth NO bm bm
? Time:
? m=d DFS typically wins
:might winguara n t e e s ,
g
m>dllenBFS
a e s
Cmh= ’
?
e t B F S o r y ? ?
?
∞
w to g
BFS probably
s m em
better
Ho ’
?
n l y D F S
? Space
u si n g o
? DFS almost always beats BFS
19
Which Strategy to Use?
? Depends on problem.
? If there are infinite paths
⇒ depth-first is bad
? If goal is at known depth
⇒ depth-first is good
? If ∃ large (possibly ∞) branching factor
⇒ breadth-first is bad
20
Depth- Limited S trategy
? Depth-first with depth cut-off k
(do NOT expand nodes below depth k)
21
Depth-Limited Depth-First-Search
? Depth cut-off: k=3
? If not: increase k by 1
(Regenerate nodes, as necessary)
23
Iterative Deepening Search k=0
24
Iterative Deepening Search: k=1
25
Iterative Deepening Search: k =2
26
Iterative Deepening Search k=3
27
28
Iterative Deepening: Analysis
? Time: ≈ BFS !
? … even though it regenerates intermediate nodes !
? Why? Almost all work ON FINAL LEVEL anyway!
? Eg: b = 10, d = 5:
? BFS expands 1 + 10 + 100 + … + 100,000 = 111,111
? IDS expands
? bottom level: 1 time
? second to bottom: 2 times
? …
? toplevel: d+1 times
total:(d+1)b0 + d b1 + (d-1)b2 + … + 3bd-2 +2bd-1 + 1bd
… 100,000 + 20,000 + …+ 50 + 6 = 123,456
? Ratio of IDS to BFS: ≈ [b / (b-1)]2
? Cost of repeating work at shallow depths: MINOR!
29
Properties of
Iterative Deepening S earch
? Complete? Yes
? Optimal? Yes, if step cost = 1
? Time?
(d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd)
? Space? O(b d)
? IDS does not get stuck on infinite path
? Space: Same as DFS – but with d, not m
(as each search is DFS) 32
BiDirectional
S earch
? Simultaneously:
? Search “forward" from start
? Search “backward" from goal
Stop when two searches meet in middle
? If branching factor = b in each direction & solution at depth d
⇒ need only O(2bd/2) = O(bd/2) steps
? Eg: b = 10, d = 6:
BFS expands 1,111,111 nodes
BiDirectional: 2,222 !
? Issues:
? How to “search backwards from goal"?
? What if > 1 goals (chess)?
? How to check if paths meet? constant time?
? What type of search done in each half? (BFS)
33
34
Comparing “Blind" Search
Strategies
35
Comparison of S trategies
? Breadth-first is complete and optimal,
but has high space complexity
? Bad when branching factor is high
? Depth-first is space efficient,
but not complete nor optimal
? Bad when search depth is infinite
? Iterative deepening is asymptotically
optimal !
36
Avoiding Repeated States
? May reach same state thru multiple paths
1 2 3
search tree is finite search tree is infinite
4 5
7 8 6
39
S ummary of Blind S earch
? Search strategies:
? breadth-first, depth-first, iterative deepening, …
? Evaluation of strategies:
? completeness, optimality, time and space
complexity
? Iterative deepening search
? uses only linear space
? ≈ same time as other blind-searchers
? Avoid repeated states
40
41