0% found this document useful (0 votes)
34 views36 pages

Artificial Intelligence: Ms. Sania Yousuf

The document discusses different strategies for searching problem spaces in artificial intelligence, including uninformed and informed search methods. Uninformed search methods like breadth-first, depth-first, and uniform cost search do not use heuristics to guide the search. Informed search methods like A* use heuristics to try to find goal states more efficiently by heading in their general direction. The document provides examples to illustrate breadth-first, depth-first, and iterative deepening search strategies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views36 pages

Artificial Intelligence: Ms. Sania Yousuf

The document discusses different strategies for searching problem spaces in artificial intelligence, including uninformed and informed search methods. Uninformed search methods like breadth-first, depth-first, and uniform cost search do not use heuristics to guide the search. Informed search methods like A* use heuristics to try to find goal states more efficiently by heading in their general direction. The document provides examples to illustrate breadth-first, depth-first, and iterative deepening search strategies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 36

Artificial Intelligence

Ms. Sania Yousuf


Evaluating Search Strategies
• Completeness
– Guarantees finding a solution whenever one exists
• Time complexity
– How long (worst or average case) does it take to find a solution?
Usually measured in terms of the number of nodes expanded
• Space complexity
– How much space is used by the algorithm? Usually measured in terms
of the maximum size of the “nodes” list during the search
• Optimality/Admissibility
– If a solution is found, is it guaranteed to be an optimal one? That is, is
it the one with minimum cost?
Uninformed vs. Informed search
• Uninformed search strategies
– Also known as “blind search,” uninformed search strategies use no
information about the likely “direction” of the goal node(s)
– Uninformed search methods: Breadth-first, depth-first, depth-
limited, uniform-cost, depth-first iterative deepening, bidirectional
• Informed search strategies
– Also known as “heuristic search,” informed search strategies use
information about the domain to (try to) (usually) head in the
general direction of the goal node(s)
– Informed search methods: Hill climbing, best-first, greedy search,
beam search, A, A*
Uninformed Search Methods
Visited vs Expanded
Let's start with the notion of Visited as opposed to Expanded.
We say a state is visited when a path that reaches that state
(that is, a node that refers to that state) gets added to Q. So, if
the state is anywhere in any node in Q, it has been visited.
Note that this is true even if no path to that state has been
taken off of Q.

A state M is Expanded when a path to that state is pulled off


of Q. At that point, the descendants of M are visited and the
paths to those descendants added to the Q.
Example 1
Example for illustrating uninformed search strategies

Initial

final
Queue Visited Expanded
0
[0] 0 None B
[1 | 3 | 8 ] 0, 1,3,8 0 expanded unvisited child of 0 en-queue in the Queue
3 Tested for Goal (0) Not a Goal r
[3 | 8 | 7] 0,1,3,8,7 1 expanded unvisited child of 1 en-queue in Queue
Tested for Goal (1)  Not a Goal
e
2 [8 | 7 | 2 | 4] 0,1,3,8,7,2,4 3 expanded unvisited child of 3 en-queue in Queue a
Tested for Goal (3) Not a Goal
[7 | 2 | 4 ] 0,1,3,8,7,2,4 8 expanded unvisited child of 8 en-queue in Queue d
[2 | 4 ] 0,1,3,8,7,2,4
Tested for Goal (8)  Not a Goal
7 expanded unvisited child of 7 en-queue in Queue
t
Tested for Goal (7)  Not a Goal h
5 [4 | 5] 0,1,3,8,7,2,4,5 2 expanded unvisited child of 2 en-queue in Queue
Tested for Goal (2)  Not a Goal -
[5] 0,1,3,8,7,2,4,5 4 expanded unvisited child of 4 en-queue in Queue F
Tested for Goal (4)  Not a Goal
6 [6] 0,1,3,8,7,2,4,5,6 5 expanded unvisited child of 5 en-queue in Queue
i
Tested for Goal (5)  Not a Goal
r
[] 0,1,3,8,7,2,4,5,6 6 expanded unvisited child of 6 en-queue in Queue
Tested for Goal (6)  Goal (stop) s
Path 03256 t
Example for illustrating Breadth First search strategies

Initial

final
Stack Visited Expanded
[0 0 None
0 D
[1 | 3 | 8 0, 1,3,8 0 expanded unvisited child of 0 pushed in Stack

[1 | 3 | 4 0,1,3,8,4
Tested for Goal (0) Not a Goal
8 expanded unvisited child of 8 pushed in Stack
e
3 Tested for Goal (8)  Not a Goal p
[1|3 0,1,3,8,4 4 expanded unvisited child of 4 pushed in Stack
Tested for Goal (4) Not a Goal t
2 [1|2 0,1,3,8,4,2 3 expanded unvisited child of 3 pushed in Stack
Tested for Goal (3)  Not a Goal
h
5 [1|7|5 0,1,3,8,4,2,7,5 2 expanded unvisited child of 2 pushed in Stack -
Tested for Goal (2)  Not a Goal
[1|7|6 0,1,3,8,4,2,7,5, 5 expanded unvisited child of 5 pushed in Stack
F
6 6 Tested for Goal (5)  Not a Goal
i
[1|7 0,1,3,8,4,2,7,5,
6
6 expanded unvisited child of 6 pushed in Stack
Tested for Goal (6)  Goal (stop)
r
s
t
Path 03256
Example for illustrating Depth First search strategies

Initial

final
Iteration = Stack Visited Expanded
depth/level

0 [0 0 Tested for Goal (0) Not a Goal I


te
1 [0 0, 1,3,8 0 expanded unvisited child of 0 pushed in r
[1 | 3 | 8 Stack
[1|3 Tested for Goal (0) Not a Goal a
[1 Visited 8 , 3, 1 and tested for Goal. t
[
iv
e
2 [0 0,1,3,8,4,2,7 0 expanded, unvisited child of 0 pushed in
[1 | 3 | 8 Stack
[1 | 3 | 4 8 expanded unvisited child of 8 pushed in D
[1 | 3 Stack, 4 can’t be expanded as depth is 2.
[1 | 2 3 expanded unvisited child of 3 pushed in
e
[1 Stack, 2 can’t be expanded as depth is 2. e
[7 1 expanded unvisited child of 1 pushed in
[ Stack, 7 can’t be expanded as depth is 2.
p
Remember to Test for goal in each step i
n
g
Iteration = Stack Visited Expanded
depth/level
I
te
3 [0 0,1,3,8,4,2,5,6 0 expanded unvisited child of 0 pushed in r
[1 | 3 | 8 Stack a
[1 | 3 | 4 8 expanded unvisited child of 8 pushed in
[1 | 3 Stack t
[1 | 2 4 expanded unvisited child of 4 pushed in iv
[1|5|7 Stack
[1|5 3 expanded unvisited child of 3 pushed in e
[1 Stack
[ 2 expanded unvisited child of 2 pushed in
Stack D
7 expanded unvisited child of 7 pushed in e
Stack
5 visited but can’t expand because level is 3 e
1 expanded unvisited child of 1 pushed in p
Stack Remember to Test for goal in each step
i
n
g
Iteration = Stack Visited Expanded
depth/level
I
te
4 [0 0,1,3,8,4,2,5,6 0 expanded unvisited child of 0 pushed in r
0 [1 | 3 | 8 Stack a
[1 | 3 | 4 8 expanded unvisited child of 8 pushed in
[1 | 3 Stack t
[1 | 2 4 expanded unvisited child of 4 pushed in iv
3 [1|5|7 Stack
e
[1|5 3 expanded unvisited child of 3 pushed in
[1|6 Stack
2 [1 2 expanded unvisited child of 2 pushed in
D
Stack
7 expanded unvisited child of 8 pushed in e
5 Stack
e
5 expanded unvisited child of 5 pushed in
Stack p
6 6 expanded unvisited child of 5 pushed in
i
Stack ( Goal Node so stop)
Remember to Test for goal in each step n
g

Path 03256
Example for illustrating Iterative Deeping search strategies

Initial

final
Example 2
Example for illustrating uninformed search strategies
final
Initial
Breadth-First

Queue Visited Expanded


0 [0] 0 None
[1 | 3 | 8 ] 0, 1,3,8 0 expanded unvisited child of 0 en-queue in the Queue
Tested for Goal (0) Not a Goal
[3 | 8 | 7] 0,1,3,8,7 1 expanded unvisited child of 1 en-queue in Queue
1 Tested for Goal (1)  Not a Goal
[8 | 7 | 2 | 4] 0,1,3,8,7,2,4 3 expanded unvisited child of 3 en-queue in Queue
Tested for Goal (3) Not a Goal
[7 | 2 | 4 ] 0,1,3,8,7,2,4 8 expanded unvisited child of 8 en-queue in Queue
Tested for Goal (8)  Not a Goal
7 [2 | 4 ] 0,1,3,8,7,2,4 7 expanded unvisited child of 7 en-queue in Queue
Tested for Goal (7)  Goal (stop)

Path 017
Example for illustrating Breadth First search strategies
final
Initial
Stack Visited Expanded
[0 0 None
0 [1 | 3 | 8 0, 1,3,8 0 expanded unvisited child of 0 pushed in Stack
D
Tested for Goal (0) Not a Goal
[1 | 3 | 4 0,1,3,8,4 8 expanded unvisited child of 8 pushed in Stack
Tested for Goal (8)  Not a Goal
e
3 [1|3 0,1,3,8,4 4 expanded unvisited child of 4 pushed in Stack p
Tested for Goal (4) Not a Goal
[1|2 0,1,3,8,4,2 3 expanded unvisited child of 3 pushed in Stack
t
2
Tested for Goal (3)  Not a Goal
h
[1|7|5 0,1,3,8,4,2,7,5 2 expanded unvisited child of 2 pushed in Stack
Tested for Goal (2)  Not a Goal -
[1|7|6 0,1,3,8,4,2,7,5,
6
5 expanded unvisited child of 5 pushed in Stack
Tested for Goal (5)  Not a Goal
F
7
i
[1|7 0,1,3,8,4,2,7,5, 6 expanded unvisited child of 6 pushed in Stack
6 Tested for Goal (6)  Not a Goal r
[1 0,1,3,8,4,2,7,5, 7 expanded unvisited child of 7 pushed in Stack s
6 Tested for Goal (6)  Goal (stop)
t
Path 0327
Example for illustrating Depth First search strategies
final
Initial
Iteration = Stack Visited Expanded
depth/level

0 [0 0 Tested for Goal (0) Not a Goal I


te
1 [0 0, 1,3,8 0 expanded unvisited child of 0 pushed in
0 [1 | 3 | 8 Stack r
[1|3 Tested for Goal (0) Not a Goal a
[1 Visited 8 , 3, 1 and tested for Goal.
[ t
2 [0 0,1,3,8,4,2,7 0 expanded, unvisited child of 0 pushed in iv
1 [1 | 3 | 8 Stack e
[1 | 3 | 4 8 expanded unvisited child of 8 pushed in
[1 | 3 Stack, 4 visited but can’t be expanded as
[1 | 2 depth is 2. D
[1 3 expanded unvisited child of 3 pushed in
7 [7 Stack, 2 visited but can’t be expanded as
e
[ depth is 2. e
1 expanded unvisited child of 1 pushed in
Stack,
p
7 visited but can’t be expanded as depth is i
2. 7 is the goal node so stop iterations n
Remember to Test for goal in each step g
Path 017
Example for illustrating Iterative Deeping search strategies

Initial
final
Example 2
Example for illustrating uninformed search (Uniform Cost)

S
2 1 7

A D E
2 8
6 10 4
B C G
Cost from start to
node n
Uniform-Cost Search
Priority Queue Expanded
[S:0] None
[A:2 | D:1 | E:7 ] S expanded unvisited child of S en-queue in the
Sort Queue
[D:1 | A:2 | E:7] Tested for Goal (S) Not a Goal
[A:2 | E:7 | G:11] D expanded unvisited child of D en-queue in Queue
S Tested for Goal (D)  Not a Goal
[E:7 | G:11 | B:4 | C:8 | G:10] A expanded unvisited child of A en-queue in Queue
Sort Tested for Goal (A) Not a Goal
[B:4 | E:7 | C:8 | G:10 | G:11]
A [E:7 | C:8 | G:10 | G:11] B expanded (No child)
Tested for Goal (B)  Not a Goal
[C:8 | G:10 | G:11 | G:11] E expanded unvisited child of E en-queue in Queue
Tested for Goal (E) Not a Goal
G
[G:10 | G:11 | G:11] C expanded (No child)
Tested for Goal (C) Not a Goal
[G:11 | G:11] C expanded (No child)
Tested for Goal (C)  Goal node stop

Path SAG Cost : 10


Example for illustrating uninformed search (Uniform Cost)

S
2 1 7

A D E
2
6 10 4
8
B C G
Uninformed Search Methods
Breadth-First
• Enqueue nodes on nodes in FIFO (first-in, first-out) order.
• Complete
• Optimal (i.e., admissible) if all operators have the same cost. Otherwise, not optimal but
finds solution with shortest path length.
• Exponential time and space complexity, O(bd), where d is the depth of the solution and b is
the branching factor (i.e., number of children) at each node
• Will take a long time to find solutions with a large number of steps because must look at all
shorter length possibilities first
– A complete search tree of depth d where each non-leaf node has b children, has a total of 1 + b + b2
+ ... + bd = (b(d+1) - 1)/(b-1) nodes
– For a complete search tree of depth 12, where every node at depths 0, ..., 11 has 10 children and
every node at depth 12 has 0 children, there are 1 + 10 + 100 + 1000 + ... + 10 12 = (1013 - 1)/9 =
O(1012) nodes in the complete search tree. If BFS expands 1000 nodes/sec and each node uses 100
bytes of storage, then BFS will take 35 years to run in the worst case, and it will use 111 terabytes
of memory!
Depth-First (DFS)
• Enqueue nodes on nodes in LIFO (last-in, first-out) order. That is,
nodes used as a stack data structure to order nodes.
• May not terminate without a “depth bound,” i.e., cutting off search
below a fixed depth D ( “depth-limited search”)
• Not complete (with or without cycle detection, and with or without a
cutoff depth)
• Exponential time, O(bd), but only linear space, O(bd)
• Can find long solutions quickly if lucky (and short solutions slowly if
unlucky!)
• When search hits a dead-end, can only back up one level at a time even
if the “problem” occurs because of a bad operator choice near the top of
the tree. Hence, only does “chronological backtracking”
Uniform-Cost (UCS)
• Enqueue nodes by path cost. That is, let g(n) = cost of the path from
the start node to the current node n. Sort nodes by increasing value of
g.
• Called “Dijkstra’s Algorithm” in the algorithms literature and similar
to “Branch and Bound Algorithm” in operations research literature
• Complete (*)
• Optimal/Admissible (*)
• Admissibility depends on the goal test being applied when a node is
removed from the nodes list, not when its parent node is expanded
and the node is first generated
• Exponential time and space complexity, O(bd)
Depth-First Iterative Deepening (DFID)
• First do DFS to depth 0 (i.e., treat start node as having no successors),
then, if no solution found, do DFS to depth 1, etc.
until solution found do
DFS with depth cutoff c
c = c+1
• Complete
• Optimal/Admissible if all operators have the same cost. Otherwise, not
optimal but guarantees finding solution of shortest length (like BFS).
• Time complexity seems worse than BFS or DFS because nodes near the
top of the search tree are generated multiple times, but because almost
all of the nodes are near the bottom of a tree, the worst case time
complexity is still exponential, O(bd).
Depth-First Iterative Deepening
• If branching factor is b and solution is at depth d, then nodes
at depth d are generated once, nodes at depth d-1 are
generated twice, etc.
– IDS : (d) b + (d-1) b2 + … + (2) b(d-1) + bd = O(bd).
– If b=4, then worst case is 1.78 * 4d, i.e., 78% more nodes
searched than exist at depth d (in the worst case).
• However, let’s compare this to the time spent on BFS:
– BFS : b + b2 + … + bd + (b(d+1) – b) = O(bd).
– Same time complexity of O(bd), but BFS expands some
nodes at depth d+1, which can make a HUGE difference:
• With b = 10, d = 5,
• BFS: 10 + 100 + 1,000 + 10,000 + 100,000 + 999,990 = 1,111,100
• IDS: 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450
• IDS can actually be quicker in-practice than BFS,
even though it regenerates early states.
Depth-First Iterative Deepening
• Exponential time complexity, O(bd), like BFS
• Linear space complexity, O(bd), like DFS

• Has advantage of BFS (i.e., completeness) and also


advantages of DFS (i.e., limited space and finds
longer paths more quickly)
• Generally preferred for large state spaces where
solution depth is unknown
Comparing Search Strategies

b – branching factor d – depth of optimal solution


m – maximum depth l – depth limit
Graph Search Strategies
• Breadth-first search and uniform-cost search are optimal
graph search strategies.
• Iterative deepening search and depth-first search can follow
a non-optimal path to the goal.
• Iterative deepening search can be used with modification:
– It must check whether a new path to a node is better than the
original one
– If so, IDS must revise the depths and path costs of the node’s
descendants.

You might also like