AI Lecture 4

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 34

Lecture 4 – Uninformed Search

September 24, 2023 1


 Uninformed search strategies use only the
information available in the problem definition

 Breadth-first search

 Uniform-cost search

 Depth-first search

 Depth-limited search

 Iterative deepening search

September 24, 2023 2


 Expand shallowest unexpanded node
 Implementation:
 fringe is a FIFO queue, i.e., new successors go
at end

September 24, 2023 3


 Expand shallowest unexpanded node
 Implementation:
 fringe is a FIFO queue, i.e., new successors go
at end

September 24, 2023 4


 Expand shallowest unexpanded node
 Implementation:
 fringe is a FIFO queue, i.e., new successors go
at end

September 24, 2023 5


 Expand shallowest unexpanded node
 Implementation:
 fringe is a FIFO queue, i.e., new successors go
at end

September 24, 2023 6


September 24, 2023 7
 Complete? Yes (if b is finite)

 Time? 1+b+b2+b3+… +bd + b(bd-1) =


O(bd+1)

 Space? O(bd+1) (keeps every node in


memory)

 Optimal? Yes (if cost = 1 per step)

 Space is the bigger problem (more than


time).
September 24, 2023 8
 We can have search graphs (instead of trees)
 Hence paths can go backwards, ABCB
 Can get paths with loops ABCDB

 We can also have multiple paths to a node


 From them, we are interested in the min-cost
path

 The Loop problem is that we “rediscover” nodes


that the search has already discovered

 Need to consider methods to suppress nodes that


have already been visited.

September 24, 2023 9


September 24, 2023 11
Consider the following
problem…

A
1 10

5 5
S B G

15 5
C

We wish to find the shortest route from node S to node G; that is, node S is the
initial state and node G is the goal state. In terms of path cost, we can clearly
see that the route SBG is the cheapest route. However, if we let breadth-first
search loose on the problem it will find the non-optimal path SAG, assuming
that A is the first node to be expanded at level 1.
Once
Node
WeNode
Wenow
A
node
start
is
Sexpand
removed
isBwith
removed
hasour
the
been
from
initial
node
from
expanded
the
state
at
the
queue
the
queue
and
front
it and
is
expand
and
removed
ofthe
the
the
revealed
queue,
revealed
fromnode
the
node
nodes
queue
A.
(node
Press
areand
G)added
space
the
is added
revealed
totothe
to
the
node
continue.
queue.
it…
queue.
(node The
The
G)queue
isqueue
added.
isisthen
The
again
sorted
queue
sortedonisonpath
again
path
cost.
sorted
cost.
Nodes
Note,
on path
with
wecost.
cheaper
haveNote,now path
found
node cost
Ga have
goal
nowpriority.In
appears
state but this
indothe
case
notqueue
recognise
the queue
twice,itwill
once
as beit is
as
Node
not
G10atAand
the
(1),once
front
nodeof
asBthe
G(5),
11queue.
. followed
As G10 Node
isbyatnode
Bthe
is C
the(15).
frontcheaper
of Press
the queue,
node.
space. Press
we now space.
proceed to goal state. Press space.

A
1 10

5 5
S B G

The goal state is achieved and the


15 path S-B-G is returned. In relation
C to path cost, UCS has found the
optimal route.

Size of Queue: 0
1
3 Queue: Empty
S 10G
A,
B,
G B,
, 11
GC,11C, C15

Nodes expanded: 3
0
1
2 CurrentFINISHED
action: Expanding
Waiting….
Backtracking
SEARCH Current level: 2
n/a
0
1

UNIFORM COST SEARCH PATTERN


September 24, 2023 14
 Expand least-cost unexpanded node
 Implementation:
 fringe = queue ordered by path cost
 Equivalent to breadth-first if step costs all equal
 Complete? Yes, if step cost ≥ ε
 Time? O(bceiling(C*/ ε)) where C* is the cost of the
optimal solution
 Space? O(bceiling(C*/ ε))
 Optimal? Yes – given the condition of
completeness – you always expand the node
with lowest cost
 O(bceiling(C*/ ε)) can be greater than Ob/d

September 24, 2023 15


 Expand deepest unexpanded node
 Implementation:
 fringe is a LIFO queue, i.e., put successors in
the front

September 24, 2023 16


 Expand deepest unexpanded node
 Implementation:
 fringe is a LIFO queue, i.e., put successors in
the front

September 24, 2023 17


 Expand deepest unexpanded node
 Implementation:
 fringe is a LIFO queue, i.e., put successors in
the front

September 24, 2023 18


 Expand deepest unexpanded node
 Implementation:
 fringe is a LIFO queue, i.e., put successors in
the front

September 24, 2023 19


 Expand deepest unexpanded node
 Implementation:
 fringe is a LIFO queue, i.e., put successors in
the front

September 24, 2023 20


 Expand deepest unexpanded node
 Implementation:
 fringe is a LIFO queue, i.e., put successors in
the front

September 24, 2023 21


 Expand deepest unexpanded node
 Implementation:
 fringe is a LIFO queue, i.e., put successors in
the front

September 24, 2023 22


 Complete? No: fails in infinite-depth
spaces, spaces with loops
 Complete in finite spaces
 Time? O(bm): terrible if m is much larger
than d
 But if solutions are dense, may be much
faster than breadth-first
 Space? O(bm), i.e., linear space!
 Optimal? No

September 24, 2023 23


 Depth-first search with depth limit l, i.e., nodes
at depth l have no successors
 Recursive implementation:

September 24, 2023 25


 Complete? NO. Why? (l < d OR l > d)

 Time? O(bl)

 Space? O(bl)

 Depth-first is a special case of depth-limited


with l being infinite.

September 24, 2023 26


September 24, 2023 27
September 24, 2023 28
September 24, 2023 29
September 24, 2023 30
September 24, 2023 31
 Number of nodes generated in a depth-limited
search to depth d with branching factor b:
NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd

 Number of nodes generated in an iterative


deepening search to depth d with branching
factor b:
NIDS = (d+1)b0 + d b1 + (d-1)b2 + … + 3bd-2
+2bd-1 + 1bd
 For b = 10, d = 5,

N
DLS = 1 + 10 + 100 + 1,000 + 10,000 +
100,000 = 111,111
N
IDS = 6 + 50 + 400 + 3,000 + 20,000 +
100,000 = 123,456
 Overhead = (123,456 - 111,111)/111,111 =
11%
September 24, 2023 32
 Complete? Yes

 Time? (d+1)b0 + d b1 + (d-1)b2 + … + bd =


O(bd)

 Space? O(bd)

 Optimal? Yes, if step cost = 1

September 24, 2023 33


September 24, 2023 34
September 24, 2023 35

You might also like