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

CS488 CH 5 Uninformed Search

uninformed search
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

CS488 CH 5 Uninformed Search

uninformed search
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

HiLCoE

School of Computer Science and Technology

Course Title: Introduction to Artificial Intelligence (CS488)


Credit Hour: 4
Instructor: Fantahun B. (PhD) [email protected]
Office: 402
C_hrs: Tues 10:30-12:10, Thurs 13:30-15:10
13:30-15:10 10:30-12:10
Jul-2022, AA
5- Uninformed Search Strategies

Agenda
 Breadth-first search
 Uniform-cost search
 Depth-first search
 Depth-limited search
 Iterative deepening search
 Bidirectional search

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 2


5- Uninformed Search Strategies

Objectives
After successful completion of this chapter, students will be able to
explain and try to implement the following algorithms.
 Breadth-first search
 Uniform-cost search
 Depth-first search
 Depth-limited search
 Iterative deepening search
 Bidirectional search

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 3


5- Uninformed Search Strategies
 This chapter covers several search strategies that come under the
heading of uninformed search (blind search).
 These strategies have no additional information about states
beyond that provided in the problem definition.
 All they can do is generate successors and distinguish a goal state
from a non-goal state.
 All search strategies are distinguished by the order in which nodes
are expanded.
 Strategies that know whether one non-goal state is “more
promising” than another are called informed search or heuristic
search strategies; they are covered in Ch-6.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 4


5- Uninformed Search Strategies
(1) Breadth-first search

 Breadth-first search is a simple strategy in which the root


node is expanded first, then all the successors of the root
node are expanded next, then their successors, and so
on.
 In general, all the nodes are expanded at a given depth
in the search tree before any nodes at the next level are
expanded.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 5


5- Uninformed Search Strategies
(1) Breadth-first search

Figure 5.1 Breadth-first search on a graph.


Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 6
5- Uninformed Search Strategies
(1) Breadth-first search

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 7


5- Uninformed Search Strategies
(1) Breadth-first search Implementation Example:

 A standard BFS implementation puts each vertex of the graph into


one of two categories:
o Visited
o Not Visited
 Objective: mark each vertex as visited while avoiding cycles.
 Algorithm implementation:
1. Start by putting any one of the graph's vertices at the back of
a queue.
2. Take the front item of the queue and add it to the visited list.
3. Create a list of that vertex's adjacent nodes and add the
none-visited ones to the back of the queue.
4. Repeat steps 2 and 3 until the queue is empty.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 8


5- Uninformed Search Strategies
(1) Breadth-first search Implementation Example:

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 9


5- Uninformed Search Strategies
(1) Breadth-first search Implementation Example:

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 10


5- Uninformed Search Strategies
(1) Breadth-first search Implementation Example:

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 11


5- Uninformed Search Strategies
(1) Breadth-first search Implementation Example:

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 12


5- Uninformed Search Strategies
(1) Breadth-first search Implementation Example:

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 13


5- Uninformed Search Strategies
(1) Breadth-first search Implementation Example:

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 14


5- Uninformed Search Strategies
(1) Breadth-first search Implementation Example:

 Code:
 Try BFS Python implementation in the lab

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 15


5- Uninformed Search Strategies
(1) Breadth-first search

 Complete? Yes (if b is finite)


 Time complexity?
o O(bd+1)
 Space complexity?
o O(bd+1) (keeps every node in memory)
 Optimal? Yes (if cost = 1 per step); not optimal in general
 Space is the big problem; can easily generate nodes at
100MB/sec
 so 24hrs = 8640GB.
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 16
5- Uninformed Search Strategies
(1) Breadth-first search
 Imagine searching a uniform tree where every state has b
successors.
o The root of the search tree generates b nodes at the first level,
o Each of which generates b more nodes, for a total of b2 at the second level.
o b3 nodes at the third level, and so on.
 Now suppose that the solution is at depth d. In the worst case, it is
the last node generated at that level. Then the total number of
nodes generated is
b + b2 + b3 + · · · + bd = O(bd) .
 If the algorithm were to apply the goal test to nodes when selected
for expansion, rather than when generated, the whole layer of
nodes at depth d would be expanded before the goal was
detected and the time complexity would be
O(bd+1).
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 17
5- Uninformed Search Strategies
(1) Breadth-first search Time & Space

Figure 5.2 Time and memory requirements for breadth-first search. The numbers
shown assume branching factor b = 10; 1 million nodes/second; 1000 bytes/node.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 18


5- Uninformed Search Strategies
(1) Breadth-first search Time & Space
 Two lessons can be learned from Figure 5.2.
 First, the memory requirements are a bigger problem for breadth-
first search than is the execution time. One might wait 13 days for
the solution to an important problem with search depth 12, but no
personal computer has the petabyte of memory it would take.
 The second lesson is that time is still a major factor. If your problem
has a solution at depth 16, then (given our assumptions) it will take
about 350 years for breadth-first search (or indeed any uninformed
search) to find it.
 In general, exponential-complexity search problems cannot be
solved by uninformed methods for any but the smallest instances.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 19


5- Uninformed Search Strategies
(2) Uniform-cost search
 When all step costs are equal, BFS is optimal because it always
expands the shallowest unexpanded node.
 By a simple extension, instead of expanding the shallowest
node, uniform-cost search expands the node n with the
lowest path cost g(n).
 This is done by storing the frontier as a priority queue ordered
by g. The algorithm is shown in Figure 5.3.
 In addition to the ordering of the queue by path cost, there
are two other significant differences from BFS.
o the goal test is applied to a node when it is selected for expansion
rather than when it is first generated. The reason is that the first goal
node that is generated may be on a suboptimal path.
o a test is added in case a better path is found to a node currently on
the frontier.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 20


5- Uninformed Search Strategies
(2) Uniform-cost search

Figure 5.3 Uniform-cost search on a graph.


Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 21
5- Uninformed Search Strategies
(2) Uniform-cost search
 Both of these modifications come into play in the example shown in
Figure 5.4 where the problem is to get from Sibiu to Bucharest.
 The successors of Sibiu are Rimnicu Vilcea and Fagaras, with costs
80 and 99, respectively. The least-cost node, Rimnicu Vilcea, is
expanded next, adding Pitesti with cost 80 + 97=177.
 The least-cost node is now Fagaras, so it is expanded, adding
Bucharest with cost 99+211=310.
 Now a goal node has been generated, but uniform-cost search
keeps going, choosing Pitesti for expansion and adding a second
path to Bucharest with cost 80+97+101= 278.
 Now the algorithm checks to see if this new path is better than the
old one; it is, so the old one is discarded. Bucharest, now with g-
cost 278, is selected for expansion and the solution is returned.
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 22
5- Uninformed Search Strategies
(2) Uniform-cost search

Fig. 5.4 Part of the Romania state space, picked to illustrate uniform-cost search.
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 23
5- Uninformed Search Strategies
(3) Depth-first search (DFS)
 Depth-first search always expands the deepest node in the
current frontier of the search tree.
 The progress of the search is illustrated in Figure 5.5. The search
proceeds immediately to the deepest level of the search tree,
where the nodes have no successors.
 As those nodes are expanded, they are dropped from the
frontier, so then the search “backs up” to the next deepest
node that still has unexplored successors.
 The depth-first search algorithm is an instance of the graph-
search algorithm whereas breadth-first-search uses a FIFO
queue, depth-first search uses a LIFO queue (STACK).
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 24
5- Uninformed Search Strategies
(3) Depth-first search (DFS)

Figure 5.5 Illustration of depth first search on a binary tree 1/2


Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 25
5- Uninformed Search Strategies
(3) Depth-first search (DFS)

Figure 5.5 Illustration of depth first search on a binary tree 2/2


Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 26
5- Uninformed Search Strategies
(3) Depth-first search (DFS): implementation example

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 27


5- Uninformed Search Strategies
(3) Depth-first search (DFS): implementation example

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 28


5- Uninformed Search Strategies
(3) Depth-first search (DFS): implementation example

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 29


5- Uninformed Search Strategies
(3) Depth-first search (DFS): implementation example

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 30


5- Uninformed Search Strategies
(3) Depth-first search (DFS): implementation example

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 31


5- Uninformed Search Strategies
(3) Depth-first search (DFS): implementation example

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 32


5- Uninformed Search Strategies
(3) Depth-first search (DFS): implementation example

 Code?
 Recursive implementation of DFS in python
 Should be tried in the lab

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 33


5- Uninformed Search Strategies
(3) Depth-first search (DFS): evaluation
 Complete? No
o fails in infinite-depth spaces, spaces with loops
o complete in finite spaces
 Time? O(bm)
o terrible if m is much larger than d; but if solutions are dense,
may be much faster than BFS
 Space? O(bm)
o linear space! (how much memory for Fig.5.2 at 16th depth?
Compare it with BFS.
 Optimal? No. why is it not optimal?

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 34


5- Uninformed Search Strategies
(4) Depth-limited search
 The failure of depth-first search in infinite state spaces can be
alleviated by supplying depth-first search with a predetermined
depth limit ℓ.
 Nodes at depth ℓ are treated as if they have no successors -
depth-limited search.
 However, it also introduces an additional source of
incompleteness if we choose ℓ < d, that is, the shallowest goal is
beyond the depth limit. (likely when d is unknown)
 Depth-limited search will also be not optimal if we choose ℓ > d.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 35


5- Uninformed Search Strategies
(4) Depth-limited search
 Sometimes, depth limits can be based on knowledge of the
problem.
 For 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.
 But looking the map carefully, we would discover that any city
can be reached from any other city in at most 9 steps. This
number, known as the diameter of the state space, gives us a
better depth limit, which leads to a more efficient depth-limited
search.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 36


5- Uninformed Search Strategies
(4) Depth-limited search

Figure 5.6 A recursive implementation of depth-limited tree search.


Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 37
5- Uninformed Search Strategies
(4) Depth-limited search
 Complete? No
o Incomplete when ℓ < d
 Time? O(bℓ)
 Space? O(bℓ)
 Optimal? No
o Not optimal when ℓ > d

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 38


5- Uninformed Search Strategies
(5) Iterative deepening depth-first search
 Iterative deepening search (or iterative deepening depth-first
search) is a general strategy, often used in combination with
depth-first tree search, that finds the best depth limit.
 It does this by gradually increasing the limit—first 0, then 1, then 2,
and so on—until a goal is found.
 This will occur when the depth limit reaches d, the depth of the
shallowest goal node.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 39


5- Uninformed Search Strategies
(5) Iterative deepening depth-first search

Figure 5.7 The iterative deepening search algorithm, which repeatedly


applies depth-limited search with increasing limits. It terminates when a
solution is found or if the depth-limited search returns failure, meaning that
no solution exists.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 40


5- Uninformed Search Strategies
(5) Iterative deepening depth-first search
 Iterative deepening combines the benefits of depth-first and
breadth-first search.
 Like depth-first search, its memory requirements are modest: O(bd)
to be precise.
 Like breadth-first search, it is complete when the branching factor
is finite and optimal when the path cost is a non-decreasing
function of the depth of the node.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 41


5- Uninformed Search Strategies
(5) Iterative deepening depth-first search

Figure 5.8 Four iterations of iterative deepening search on a binary tree. 1/2
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 42
5- Uninformed Search Strategies
(5) Iterative deepening depth-first search

Figure 5.8 Four iterations of iterative deepening search on a binary tree. 1/2
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 43
5- Uninformed Search Strategies
(5) Iterative deepening depth-first search

Figure 5.8 Four iterations of iterative deepening search on a binary tree. 1/2
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 44
5- Uninformed Search Strategies
(5) Iterative deepening depth-first search
 Complete? Yes
 Time? O(bd)
 Space? O(bd)
 Optimal? Yes, if step cost = 1

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 45


5- Uninformed Search Strategies
(6) Bidirectional search
 The idea behind bidirectional search is to run two simultaneous
searches—one forward from the initial state and the other
backward from the goal—hoping that the two searches meet in
the middle (Figure 5.9).
 The motivation is that bd/2 + bd/2 is much less than bd, or in the
figure, the area of the two small circles is less than the area of one
big circle centered on the start and reaching to the goal.
 Bidirectional search is implemented by replacing the goal test with
a check to see whether the frontiers of the two searches intersect;
if they do, a solution has been found.
 (The first such solution found may not be optimal, even if the two
searches are both breadth-first; some additional search is required
to make sure there isn’t another short-cut across the gap.)
Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 46
5- Uninformed Search Strategies
(6) Bidirectional search

Figure 5.9 A schematic view of a bidirectional search that is about to succeed


when a branch from the start node meets a branch from the goal node.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 47


5- Uninformed Search Strategies
(6) Bidirectional search
 For example, if a problem has solution depth d=6, and each
direction runs breadth-first search one node at a time, then in the
worst case the two searches meet when they have generated all
of the nodes at depth 3.
 For b=10, this means a total of 2,220 node generations, compared
with 1,111,110 for a standard breadth-first search.
 We can reduce this by roughly half if one of the two searches is
done by iterative deepening, but at least one of the frontiers must
be kept in memory so that the intersection check can be done.
 This space requirement is the most significant weakness of
bidirectional search.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 48


5- Uninformed Search Strategies
Comparing uninformed search strategies

Figure 5.10 Evaluation of tree-search strategies. b is the branching factor; d is the depth of
the shallowest solution; m is the maximum depth of the search tree; ℓ is the depth limit.
Superscript caveats are as follows: a complete if b is finite; b complete if step costs ≥ ε for
positive ε; c optimal if step costs are all identical; d if both directions use breadth-first search.

Jul-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 49

You might also like