Artificial Intelligence: Ms. Sania Yousuf
Artificial Intelligence: Ms. Sania Yousuf
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 03256 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 03256
Example for illustrating Depth First search strategies
Initial
final
Iteration = Stack Visited Expanded
depth/level
Path 03256
Example for illustrating Iterative Deeping search strategies
Initial
final
Example 2
Example for illustrating uninformed search strategies
final
Initial
Breadth-First
Path 017
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 0327
Example for illustrating Depth First search strategies
final
Initial
Iteration = Stack Visited Expanded
depth/level
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
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