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

Lecture 3

Uploaded by

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

Lecture 3

Uploaded by

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

Lecture3

Uninformed vs. Informed Search

11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 1


Uninformed vs. Informed Search
• Uninformed Search Strategies
– Breadth-First search
– Depth-First search
– Uniform-Cost search
– Depth-First Iterative Deepening search
• Informed Search Strategies
– Hill climbing
– Best-first search
– Greedy Search
– Beam search
– Algorithm A
– Algorithm A*
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 2
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 3
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 4
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 5
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 6
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 7
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 8
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 9
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 10
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 11
Example Illustrating Uninformed Search Strategies

S
1 5 8

A B C
3 9
7 4 5
D E G

11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 12


Breadth-First
• Algorithm outline:
– Always select from the OPEN the node with the smallest depth for
expansion, and put all newly generated nodes into OPEN
– OPEN is organized as FIFO (first-in, first-out) list, I.e., a queue.
– Terminate if a node selected for expansion is a goal
• Properties
– Complete
– Optimal (i.e., admissible) if all operators have the same cost.
Otherwise, not optimal but finds solution with shortest path
length (shallowest solution).
– Exponential time and space complexity,
O(b^d) nodes will be generated, where
d is the depth of the solution and
b is the branching factor (i.e., number of children) at each
node
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 13
Breadth-First
s
– A complete search tree of 1
depth d where each non-leaf 1 b
node has b children, has a
2
total of 1 + b + b^2 + ... + b^d b^2
= (b^(d+1) - 1)/(b-1) nodes
– Time complexity (# of nodes
generated): O(b^d)
– Space complexity (maximum
length of OPEN): O(b^d) d b^d

– 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 = (10^13 - 1)/9 =
O(10^12) nodes in the complete search tree.
• BFS is suitable for problems with shallow solutions
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 14
Breadth-First Search

exp. node OPEN list CLOSED list


{S} {}
S {ABC} {S}
A {BCDEG} {S A}
B { C D E G G' } {S A B}
C { D E G G' G" } {S A B C}
D { E G G' G" } {S A B C D}
E { G G' G" } {S A B C D E}
G { G' G" } {S A B C D E}
Solution path found is S A G <-- this G also has cost 10
Number of nodes expanded (including goal node) = 7
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 15
CLOSED List: the search tree connected by backpointers

S
1 5 8

A B C
3 9
7 4 5

D E G G’ G”

11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 16


Depth-First (DFS)
• Algorithm outline:
– Always select from the OPEN the node with the
greatest depth for expansion, and put all newly
generated nodes into OPEN
– OPEN is organized as LIFO (last-in, first-out) list.
– Terminate if a node selected for expansion is a goal goal
• May not terminate without a "depth bound," i.e., cutting off search
below a fixed depth D (How to determine the depth bound?)
• Not complete (with or without cycle detection, and with or without
a cutoff depth)
• Exponential time, O(b^d), but only linear space, O(b^d), required
• Can find deep solutions quickly if lucky
• When search hits a deadend, 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"
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 17
Depth-First Search
return GENERAL-SEARCH(problem, ENQUEUE-AT-FRONT)
exp. node OPEN list CLOSED list
{S}
S
S {ABC}
1 8
5
A { D E G B C}
A B C
D {EGBC} 3 9
7
E {GBC}
D E G
G {BC}

Solution path found is S A G <-- this G has cost 10


Number of nodes expanded (including goal node) = 5
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 18
Uniform-Cost (UCS)
• Let g(n) = cost of the path from the start node
to an open node n
• Algorithm outline:
– Always select from the OPEN the node with the least g(.) value
for expansion, and put all newly generated nodes into OPEN
– Nodes in OPEN are sorted by their g(.) values (in ascending
order)
– Terminate if a node selected for expansion is a goal
• Called “Dijkstra's Algorithm” in the algorithms
literature and similar to “Branch and Bound
Algorithm” in operations research literature
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 19
Uniform-Cost Search
GENERAL-SEARCH(problem, ENQUEUE-BY-PATH-COST)
exp. node nodes list CLOSED list
{S(0)}
S {A(1) B(5) C(8)} S
A {D(4) B(5) C(8) E(8) G(10)} 1
5 8

D {B(5) C(8) E(8) G(10)} A B C


B {C(8) E(8) G’(9) G(10)} 3
7
9 4 5
C {E(8) G’(9) G(10) G”(13)} D E G G’ G”
E {G’(9) G(10) G”(13) }
G’ {G(10) G”(13) }
Solution path found is S B G <-- this G has cost 9, not 10
Number of nodes expanded
11/10/2024 11:56:54 AM
(including goal node) = 7 20
Dr.Nadir Kamal Salih
Uniform-Cost (UCS)
• Complete (if cost of each action is not infinitesimal)
– The total # of nodes n with g(n) <= g(goal) in the state space is finite
– If n’ is a child of n, then g(n’) = g(n) + c(n, n’) > g(n)
– Goal node will eventually be generated (put in OPEN) and selected
for expansion (and passes the goal test)
• Optimal/Admissible
– Admissibility depends on the goal test being applied when a node is
removed from the OPEN list, not when it's parent node is expanded
and the node is first generated (delayed goal testing)
– Multiple solution paths (following different backpointers)
– Each solution path that can be generated from an open node n will
have its path cost >= g(n)
– When the first goal node is selected for expansion (and passes the
goal test), its path cost is less than or equal to g(n) of every OPEN
node n (and solutions entailed by n)
• Exponential time and space complexity, O(b^d) where d is the
depth of the solution path
11/10/2024 11:56:54 AM
of the least cost solution
Dr.Nadir Kamal Salih 21
Depth-First Iterative Deepening (DFID)
• BF and DF both have exponential time complexity O(b^d)
BF is complete but has exponential space complexity
DF has linear space complexity but is incomplete
• Space is often a harder resource constraint than time
• Can we have an algorithm that
– Is complete
– Has linear space complexity, and
– Has time complexity of O(b^d)
• DFID by Korf in 1985 (17 years after A*)
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 bound c
c = c+1
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 22
Depth-First Iterative Deepening (DFID)
• Complete (iteratively generate all nodes up to
depth d)
• Optimal/Admissible if all operators have the same
cost. Otherwise, not optimal but does guarantee
finding solution of shortest length (like BF).
• Linear space complexity: O(bd), (like DF)
• Time complexity is a little 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(b^d)
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 23
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., and node at depth 1 is generated
d times.
Hence
total(d) = b^d + 2b^(d-1) + ... + db
<= b^d / (1 - 1/b)^2 = O(b^d).
– If b=4, then worst case is 1.78 * 4^d, I.e., 78% more
nodes searched than exist at depth d (in the worst case).
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 24
tota (d ) 1 b d  2 b d  1    (d  1) b 2  d b
b d (1  2 b  1    (d  1) b 2 d  d b1 d )
Let x b  1 , then
tota (d ) b d (1  2 x1    (d  1) x d  2  d x d  1 )
d
b d
(x  x2   xd  1  xd )
dx
d 1
d ( x  x )
b d
dx 1  x
d d x
b / * x d 1  1 when d is large since 1 / b  1* /
dx 1  x
1(1  x)  x ( 1)
b d 2
. Therefore
(1  x)
tota (d ) b d /(1  x) 2 b d /(1  b  1 ) 2
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 25
Comparing Search Strategies

11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 26


When to use what

• Depth-First Search:
– Many solutions exist
– Know (or have a good estimate of) the depth of solution
• Breadth-First Search:
– Some solutions are known to be shallow
• Uniform-Cost Search:
– Actions have varying costs
– Least cost solution is the required
This is the only uninformed search that worries about costs.
• Iterative-Deepening Search:
– Space is limited and the shortest solution path is required

11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 27


Bi-directional search

• Alternate searching from the start state toward the goal


and from the goal state toward the start.
• Stop when the frontiers intersect.
• Works well only when there are unique start and goal
states and when actions are reversible
• Can lead to finding a solution more quickly (but watch
out for pathological situations.
11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 28
Avoiding Repeated States
• In increasing order of effectiveness in reducing size of
state space (and with increasing computational
costs.)
1. Do not return to the state you just came from.
2. Do not create paths with cycles in them.
3. Do not generate any state that was ever created
before.
• Net effect depends on ``loops'' in state-space.

11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 29


A State Space that Generates an
Exponentially Growing Search Space

11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 30


The end

11/10/2024 11:56:54 AM Dr.Nadir Kamal Salih 31

You might also like