solving problem by search
solving problem by search
Searching
Today’s
Agenda
• Searching for Solutions
• Uninformed Search Strategies
• Breadth First Search
• Depth First Search
• Uniform Cost Search (UCS)
• Depth Limited Search
• Iterative Deepening Search
Searching For
Solutions
• Having formulated some problems…how do we
solve them?
Queue-FIFO List
Front
Breadth-First
Search
Queue-FIFO List
A
Front
Breadth-First
Search
Queue-FIFO List
A B
Front
Breadth-First
Search Root
Depth 0 Level 0
Leaf Nodes
Depth 2 Level 2
Queue-FIFO List
A B C D E F G
Front
Properties of Breadth-First
Search
• Complete
• Yes if b (max branching factor) is finite
• But it wouldn’t be if the branching factor for any node was infinite
• Time
• 1 + b + b2 + … + bd + b(bm-1) = O(bm+1)
• O(bm+1) : Must examine every node in the tree
• exponential in m
Properties of Breadth-First
Search
• Space
• O(bm+1)
• Keeps every node in memory
• This is the big problem; an agent that generates nodes at 10 MB/sec
will produce 864000 MBs in 24 hours
• Optimal
• Yes (if cost is 1 per step); not optimal in general
Using Breadth-First
Search
• When is BFS appropriate?
• space is not a problem
• it’s necessary to find the solution with the fewest arcs
• although all solutions may not be shallow, at least some
are
• When is BFS inappropriate?
• space is limited
• all solutions tend to be located deep in the tree
• the branching factor is very large
Lessons From Breadth First
Search
• The memory requirements are a bigger problem for
breadth-first search than is execution time
Stack
Output
Depth-First
Search
Root-> Left Child -> Right child
Stack
Output A
Depth-First
Search
B
Active
A
Paused
Stack
Output A B
Depth-First
Search
D
D Active
B
B Paused
A
A
Paused
Stack
Output A B D
Depth-First
Search
H Active
D Paused
B
A
Paused
Paused
Stack
Output A B D H
Depth-First
Search
D Active
B Paused
A
Paused
Stack
Output A B D H
Depth-First
Search
I Active
D Paused
B
Paused
A
Paused
Stack
Output A B D H I
Depth-First
Search
D Active
B Paused
A
Paused
Stack
Output A B D H I
Depth-First
Search
B Active
A
Paused
Stack
Output A B D H I
Depth-First
Search
B Active
A
Paused
Stack
Output A B D H I
Depth-First
Search
E Active
B Paused
A
Paused
Stack
Output A B D H I E
Depth-First
Search
J Active
E Paused
B
A
Paused
Paused
Stack
Output A B D H I E J
Depth-First
Search
E Active
B Paused
A
Paused
Stack
Output A B D H I E J
Depth-First
Search
• Complete?
• Time Complexity?
• if the maximum path length is m and
the maximum branching factor is b
• O(bm+1)
Depth First
Search
• Space
• O(bm)
• Optimal
• No
Using Depth-First
Search
• When is DFS appropriate?
• space is restricted
• solutions tend to occur at the same depth in the tree
• When is DFS inappropriate?
• some paths have infinite length
• the graph contains cycles
• some solutions are very deep, while others are very
shallow
Uniform Cost Search
• Same idea as the algorithm for breadth-first
search…but…
• Expand the least-cost (g(n)) unexpanded node
• FIFO queue is ordered by cost
• What if all step costs are equal?
• Equivalent to regular breadth-first search if all step
costs are
equal
Uniform Cost Search
A
5 9
4
2 3
B C D
2 3 4 3
7
E G1 F G2
A
5 9
4
Uniform Cost B
2 C 3
D
Search A
2 3
7 4 3
G 1 G
5 9 E F
4 2
B 5 C 4
3 D
7 9
2 3
2
G1
E 11 D
G1 7
7 C 8 3
7 4
GOA
L F G2
11 10
Visited List
A C B
E D
Uniform Cost Search
• Complete
• Yes
• Time
• Let C* be the cost of the optimal solution
• assume that every action costs at least ε
•O(b1+(C*/ ε))
• Space
•O(b1+(C*/ ε))
• Optimal
• Yes
• Time and space complexity when all costs are
equal? It is similar to bfs, except that the latter
stops as soon as it generates a goal, whereas
uniform-cost search examines all the nodes at the
goal’s depth to see if one has a lower cost
O(b1+(C*/ ε)) = bd+1
Depth Limited Search (DLS)
•Same as DFS with level limitation or depth
limit.
• Search is limited up to some predetermined
level l .
• Nodes at depth l have no successors.
• Alleviates the problem of unbounded trees
A Level 0
B C D
Level 1
E F H I
Level 2 l
=2
Stack G1 J K L G2
Level 3
Output
Depth Limited Search
(DLS)
•Limitation-> If goal node is located after the
height limit, it will fail.
•Benefit-> Will not go into infinite loops.
•Same as depth-first search if l = ∞
Depth-Limited Search
• Complete
• DLS search algorithm is complete if the solution is above
the depth-limit.
• Time
• O(bl)
• Space
• O(bl)
• Optimal
• Not
even
if l >
d
Depth Limited Search
•How to choose l ?
• based on knowledge
of the problem
• example, on the map
of Romania there are
20 cities. Therefore,
we know that if there
is a solution, it must
be of length 19 at the
longest, so = 19 is a
possible choice
Iterative Deepening Search
(IDS)
• Iterative deepening depth-first search
• Uses depth-first search
• Finds the best depth limit
• Gradually increases the depth limit; 0, 1, 2, … until a goal is
found
Iterative Deepening Search
1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
Iterative Deepening
Search
Iterative Deepening
Search
Iterative Deepening
Search
Iterative Deepening
Search
Iterative Deepening
Search
• Complete
• Yes
• Time
• O(bd)
• Space
• O(bd)
• Optimal
• Yes if
step
cost
=1
Lessons From Iterative
Deepening Search
• Faster than BFS even though IDS generates
repeated states
• BFS generates nodes up to level d+1
• IDS only generates nodes up to level d