L3 Search1 Uninformed
L3 Search1 Uninformed
to Artificial
Dr. Sahar Kamal Intelligence
Searching Strategies
Lecture 3
Search Strategies
➢ Breadth-first search
Uninformed ➢ Depth-first search
Some ➢ Uniform Cost search
path ➢ Depth-limited search
➢ Iterative deepening search
➢ Bi-directional search
➢ Minimax search
Games ➢ Alpha-beta search 38
Uninformed search
strategies
Uninformed (blind):
You have no clue whether one non-goal state is better than
any other. Your search is blind. You don’t know if your current
exploration is likely to be fruitful.
Various blind strategies:
Breadth-first search
Uniform-cost search
Depth-first search
Iterative deepening search (generally preferred)
Bidirectional search (preferred if applicable)
4
Search strategy evaluation
A search strategy is defined by the order of node expansion
5
Queue for Frontier
6
General Search Problem
A Basic Search Problem
• Suppose we want to find some path from one
city to another using a highway map as the one
shown in the following figure:
Search Tree
Network
(graph)
1 1 1 3
S 5 C 2 G
3 2 0
1 3 3 4
B E
2 1
2
• Uninformed Search
– Also called blind, exhaustive or brute-force
– Makes use of no information about the problem
– May be quite inefficient
• Informed Search
– Also called heuristic or intelligent
– Uses information about the problem to guide the search
– Usually guesses the distance to a goal state
– Not always possible (depends on whether there is
information or not)
1. Breadth-First Search
• All nodes at a particular depth are expanded
before any below them
• 2 questions:
– What is the algorithm?
– How does BFS perform?
• Completeness
• Optimality
• Complexity Breadth-first search tress after
0, 1, 2, and 3 node expansions (b=2, d=2)
1. Breadth-first search
Features
Completeness: Yes
Time complexity: bd+1
Space complexity: bd
Optimality: No
2. Depth First Search
Implementation:
frontier = LIFO queue, i.e., put successors at front
Implementation:
frontier = LIFO queue, i.e., put successors at front
Implementation:
frontier = LIFO queue, i.e., put successors at front
Implementation:
frontier = LIFO queue, i.e., put successors at front
Depth-first-search
open = [start];
close = [];
while open []
remove leftmost state from open, call it X;
put X on closed;
if X is goal return SUCCESS
else
generate children of X;
discard children if on closed or open;
put remaining children on left end of open;
return FAIL
51
2. Depth-First Search
❑ Many problems have very deep or even infinite search trees.
❑ One problem with DFS is that it can get stuck going down the
wrong path.
❑ DFS should be avoided for search trees with large or
infinite maximum depths.
❑ It is common to implement a DFS with a recursive
function that calls itself on each of its children in turn.
•Completeness: No
•Time complexity: bm
•Space complexity: bm
•Optimality: No
(b-branching factor, m-max depth of tree)
Properties of depth-first search
Complete? Time? Space?Optimal?
Complete? No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated states along path (graph search)
→ complete in finite spaces
Time? O(bm): terrible if maximum depth m is much larger than solution depth d
but if solutions are dense, may be much faster than breadth-first
Space? O(bm), i.e., linear space! Store single path with unexpanded siblings.
Seems to be common in animals and humans.
Optimal? No.
Important for exploration (on-line search).
•Uniform-Cost Search
• 3. Uniform Cost Search
❑ Similar to breadth first, but takes path cost into account
❑ BFS finds the shallowest goal state.
❑ Uniform cost search modifies the BFS by expanding the lowest cost node First (as
measured by the path cost g(n))
❑ The cost of a path must never decrease as we traverse the path, i.e. no negative
cost should be in the problem domain
•Completeness: Yes
•Time complexity: # of nodes with path n cost g ≤ cost of optimal solution, O(b1
+ [C*/ε]) where C* is the cost of the optimal solution
•Space complexity: # of nodes with g ≤ cost of optimal solution, O(b1 + [C*/ε])
•Optimality: Uniform-cost search is always optimal as it only selects a path with the
lowest path cost.
UCS Example
Open list: C
UCS Example
Open list: S(5) N(5) R(6) Z(6) F(6) D(8) G(7) L(10)
UCS Example
• IDS is a strategy that sidesteps the issue of choosing the best depth limit by trying
all possible depth limits: first depth 0, then depth 1, the depth 2, and so on.
• For b = 10, d = 5,
• NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
• NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450
O (b d )
5. Iterative Deepening Search
• IDS may seem wasteful, because so many states are expanded
multiple times.
•Completeness: Yes
•Time complexity: bd
•Space complexity: bd
•Optimality: Yes
Comparison of Search Techniques
DFS BFS UCS IDS
Complete N Y Y Y
Optimal N N Y N
Heuristic N N N N