Artificial Intelligence DITI 1113: Uniformed Search II
Artificial Intelligence DITI 1113: Uniformed Search II
DITI 1113
Uniformed Search II
Dr. Zahriah binti Sahri
[email protected]
Lesson Outcomes
• Understand the theory of uninformed search
• Expanded node
• Terminated node
Depth-First Search Weakness
1. Incomplete if it searches down a path that has infinite length.
Depth-First Search Weakness
2. Missing shorter path to a goal
A
A
B C
B C
D E F G H
D E F G H
VS
I J K L M N Goal
I J K L M N
Goal Q R S T U V
BFS
DFS Y Z
Alternative Search?
Depth-Limited Search
Depth-Limited Search
• The strategy:-
– a variant of Depth First Search
– expands the deepest unexpanded node in the current frontier of the
search tree up to a predetermined depth limit l ,
– nodes at depth l are treated as if they have no successors.
– if the search reaches a node at depth l where the path is not a
solution, backtrack to the next node at depth < l .
Depth-Limited Search
• The implementation:-
– Frontier is a last-in-first-out (LIFO) queue, i.e., new successors go at
the end of the frontier successor list.
– The goal test is applied to each node when it is generated.
– For equally deepest nodes, use the left to right branching search.
Depth-Limited Search
• The algorithm:-
Source : https://www.hackerearth.com/practice/algorithms/graphs/breadth-first-search/tutorial/
What to Search?
A Start
• Search a path from A to N
B C
D E F G H
I J K L M N O P
Goal
Q R S T U V W X
Y Z
Depth Limited Search
• The search begins:- 1. Assume l = 3
10. Frontier = {G,H}. G,H are equally deepest, not goal, and at l
l=1 B C =2 < 3. Expands G.
12. Frontier = {N,H}. N is the deepest, and is the goal node. Stop
the search.
l=3 I J K L M N Goal
13. Traversed path = {ABDIEJKLFCGMN}
– Time Complexity?
O(bl)
– Space Complexity
• O(bl)
– Optimal?
• No if l > d
Depth Limited Search
• Weaknesses:-
l=0 A Start
1. Predetermined depth l is too
small, goal is not found/reached l=1 B C
• e.g if l = 2; all nodes (D,E,F,G,H) at this
level will not be expanded, hence N is l=2 D E F G H
not reached
l=3 I J K L M N O P
Goal
l=4 QR S T U V W X
l=5 Y Z
Depth Limited Search
• Weakness 2:-
l=0 A Start
– predetermined depth l is too large,
longer solution path l=1 B C
• e.g if l = 5; some nodes at deeper
levels than depth d are expanded, l=2 D E F G H
hence the traversed path to goal N is
longer.
l=3 I J K L M N O P
• d= depth of the least cost solution Goal
• d= 3 for this example
l=4 QR S T U V W X
l=5 Y Z
Depth-Limited Search
• Suitable to use when:-
– d, the depth level of the goal node is not known
– search space is large
– space (memory) is restricted
Iterative Deepening Search
• The strategy:-
– combine the space efficiency of depth-first search with the optimality
of breadth-first search
– progressively increases the depth limit l with each iteration until it
reaches the goal .
– a variant of Depth First search
Iterative Deepening Search
• The implementation:-
– Frontier is a last-in-first-out (LIFO) queue, i.e., new successors go at
the end of the frontier successor list.
– The goal test is applied to each node when it is generated.
– For equally deepest nodes, use the left to right branching search.
– First tries depth l = 0, l = 1, then l = 2, then l = 3, etc. until a goal is
found.
– Goal will be found when l = d, where d = depth of the least-cost
solution
Iterative Deepening Search
• The search begins:-
Iterative Deepening Search
• The search continues:-
Iterative Deepening Search
The properties
– Complete?
• Yes it always reaches goal (if b is finite) where b= maximum branching factor of
the search tree
– Time Complexity?
• O(bd) where d= depth of the least-cost solution
– Space Complexity
• O(bd)
– Optimal?
• Yes (if cost is 1 per step); not optimal in general
Testing Your Understanding
• Find the traversed path and the solution path from S to G using
Iterative Deepening Search :-
Bi-Directional Search
• The strategy:-
―searches in two directions simultaneously.
― one forward from the initial state and the other backward from the
goal.
―stop when both “meet in the middle”.
What to Search?
A Start
• Search a path from A to N
B C
D E F G H
I J K L M N O P
Goal
Q R S T U V W X
Y Z
Bi-Directional Search
• Forward search using Breadth- • Backward search using Breadth-
First Search:- First Search:-
A N
B C G
C
D E F
Node C is found at both forward and backward search.
Stop the search
The solution path = ACGN
Bi-Directional Search
The properties
– Complete?
• Yes, if b is finite, and both direction use BFS
– Time Complexity?
• O(bd/2) since each search need only to proceed to half of the solution path.
• d = depth of the least cost solution
– Space Complexity
• O(bd/2)
– Optimal?
• Yes, if all step cost are equal, and both direction use BFS.
Bi-Directional Search
• Advantages:-
– It requires less memory.
– It is speedier.
–Can combine different search strategies in different directions.
Bi-Directional Search
• Disadvantages:-
― Doesn't work well when goal state is not unique (example: chess).
― Implementation is difficult because additional logic must be included to decide which search tree
to extend at each step.
― Must be too efficient to find the intersection of the two search trees.
Alternative Solution?
Uniform-Cost Search
How?
Expand the least-cost unexpanded node.
FIFO queue is ordered by cost.
Equivalent to regular breadth-first search if all step
costs are equal.
Only use info found in problem definition. 32
Uniform Cost Search
• The search begins: 1.
2.
Start with initial state
Expand A, B, C.
3. Visit A and expand G.
4. Visit B and expand G.
5. Least-cost path: S-B-G
6. Path cost ,
g(n) = S-B + B-G
=5+5
= 10
The Search : Uniform Cost Search
34
Properties of Uniform-Cost Search
• Complete?
– Yes if the cost is greater than some threshold
– step cost >= ε
• Time?
– Complexity cannot be determined easily by b or d
– Let C* be the cost of the optimal solution
– O(bceil(C*/ ε))
• Space?
– O(bceil(C*/ ε))
• Optimal?
– Yes, Nodes are expanded in increasing order
35
Test Your Understanding
• Find the traversed path and the solution path from S to G using
Bi-Directional Search :-