Uninformed Search Strategies-20211124125231
Uninformed Search Strategies-20211124125231
Uninformed Search
Strategies
Session 02
1
Learning Outcomes
2
Outline
1. Problems Example
2. Searching Algorithms for Solutions
3. Uninformed Search Strategies
4. Summary
3
Problem Example 1
9l
5l
3l
Problem:
Using these three buckets, how to measure 7 liters of water
4
Problem Example 1
• Which Solution do you prefer?
• Solution 1: • Solution 2:
__a b c___ a b c
0 00 start 0 0 0 start
3 00
0 5 0
0 03
3 2 0
3 03
3 0 2
0 06
3 06 3 5 2
0 36 3 0 7 goal
3 36
1 56
0 57
goal
5
Problem Example 2
• Farmer, Goat, Tiger and Vegetables
• A farmer is going to take a goat, a tiger, and vegetables
across a river using raft. The raft can only take farmer, and
one passenger.
If the farmer is being left by, goat will be eaten by tiger, and
vegetables will be eaten by goat.
6
Problem Example 3
• Traveling from Arad to Bucharest
• Find solution:
sequence of cities, such that total driving distance is minimized
7
Problem Example 4
• 8-Puzzle
11
Uninformed Search
Strategies
1. Breadth-First Search Algorithm
1. Set Node-List to the initial state
2. Until a goal is found or Node-List is empty, do :
a. Remove the first element of Node-List and call it
E. If Node-List was empty, quit
b. For each rule match against E, do :
• Apply the rule to generate a new state
• If the new state is a goal, quit and return it
• Else, add the new state to the end of Node-List
12
Uninformed Search
Strategies
• Breadth-First Search Algorithm Illustration
S
A D
B D A E
C E E B B F
D F B F C E A C G
G C G F
G
Move downwards, level by level, until goal is reached. 13
Uninformed Search
Strategies
• Example of Breadth-First Search Tree
14
Uninformed Search
Strategies
• Time Complexity of Breadth-First Search
• If a goal node is found on depth d of the tree, all nodes up till
that depth are created.
d
m
b G
• Thus: O(bd)
15
Uninformed Search
Strategies
• Space Complexity of Breadth-First Search
• Largest number of nodes in QUEUE is reached on the level d
of the goal node.
d
b G
m
17
Uninformed Search
Strategies
• 2. Uniform-cost Search Algorithm
procedure UniformCostSearch(Graph, root, goal)
node := root, cost = 0
frontier := priority queue containing node only
explored := empty set
do
if frontier is empty
return failure
node := frontier.pop()
if node is goal
return solution
explored.add(node)
for each of node's neighbors n
if n is not in explored
if n is not in frontier
frontier.add(n)
else if n is in frontier with higher cost
replace existing node with n 18
Uninformed Search
Strategies
Properties of Uniform-cost Search
• Completeness : Yes, if step cost >0
• Time complexity : # nodes with g cost of optimal
solution, O(b d)
• Space complexity : # nodes with g cost of optimal
solution, O(b d)
• Optimality : Yes, as long as path cost never decreases
19
Uninformed Search
Strategies
Implementation of Uniform-cost Search
• Initialize Queue with root node (built from start state)
• Repeat until (Queue empty) or (first node has Goal state):
– Remove first node from front of Queue
– Expand node (find its children)
– Reject those children that have already been
considered, to avoid loops
– Add remaining children to Queue, in a way that keeps
entire queue sorted by increasing path cost
• If Goal was reached, return success, otherwise failure
20
Uninformed Search
Strategies
3. Depth-First Search Algorithm
1. If the initial state is a goal state, quit and return
success
2. Otherwise, do the following until success or failure is
signaled :
a. Generate a successors, E, of the initial state. If
there are no more successors, signal failure
b. Call Depth-First Search with E as the initial state
c. If success is returned, signal success. Otherwise
continue in this loop
21
Uninformed Search
Strategies
3. Depth-First Search Algorithm
C E
D F
G
22
Uninformed Search
Strategies
Properties of Depth-First Search Algorithm
• Completeness : No, fails in infinite state-space
(yes if finite state space)
• Time complexity : O (b m)
• Space complexity : O (bm)
• Optimality : No
Remember:
b = branching factor
m = max depth of search tree
23
Uninformed Search
Strategies
Time Complexity of Depth-First: details
• In the worst case:
• The (only) goal node may be on the right-most branch,
b m
b-1
24
Uninformed Search
Strategies
Space Complexity of Depth-First
• Largest number of nodes in QUEUE is reached in bottom left-most
node.
• Example: m = 3, b = 3 :
...
• QUEUE contains all nodes. Thus: 7.
• In General: ((b-1) * m) + 1
• Order: O(m*b) 25
Uninformed Search
Strategies
4. Depth Limited Search (DLS)
• Depth-limited search algorithm is to explore the vertices of a
graph. It is a modification of depth-first search and is used for
example in the iterative deepening depth-first search algorithm.
• Depth-limited search is works exactly like depth-first search, but
avoids its drawbacks regarding completeness by imposing a
maximum limit on the depth of the search. Even if the search
could still expand a vertex beyond that depth, it will not do so
and thereby it will not follow infinitely deep paths or get stuck in
cycles.
• Depth-limited search will find a solution if it is within the depth
limit, which guarantees at least completeness on all graphs.
26
Uninformed Search
Strategies
DLS Algorithm (Informal)
1. Determine the vertex where the search should start and
assign the maximum search depth
2. Check if the current vertex is the goal state
– If not: Do nothing
– If yes: return
3. Check if the current vertex is within the maximum search
depth
– If not: Do nothing
– If yes:
• Expand the vertex and save all of its successors in a stack
• Call DLS recursively for all vertices of the stack and go
back to Step 2
27
Uninformed Search
Strategies
Pseudocode of DLS
DLS(node, goal, depth) {
if ( depth >= 0 ) {
if ( node == goal )
return node
for each child in expand(node)
DLS(child, goal, depth-1)
}
}
28
Uninformed Search
Strategies
Properties of DLS
Space complexity
• Since depth-limited search internally uses
depth-first search, the space complexity is equivalent to
that of normal depth-first search.
Time complexity
• Since depth-limited search internally uses depth-first-
search, the time complexity is equivalent to that of normal
depth-first search, and is O(|V| + |E|) where |V| stands
for the number of vertices and for the number of edges in
the explored graph. Note that depth-limited search does
not explore the entire graph, but just the part that lies
within the specified bound.
29
Uninformed Search
Strategies
5. Iterative Deepening Search
Function Iterative-deepening-Search(problem) returns a solution, or failure
for depth = 0 to do
result Depth-Limited-Search(problem, depth)
if result succeeds then return result
end
return failure
31
Uninformed Search
Strategies
Iterative Deepening Complexity
• In iterative deepening, nodes at bottom level are expanded
once, level above twice, etc. up to root (expanded d+1
times) so total number of expansions is:
(d+1)1 + (d)b + (d-1)b^2 + … + 3b^(d-2) + 2b^(d-1) + 1b^d =
O(b^d)
32
Uninformed Search
Strategies
Comparing Uninformed Search Strategies
Criterion Breadth Uniform Depth- Depth- Iterative Bidirectional
-First Cost First Limited Deepening (if applicable)
Time b^d b^d b^m b^l b^d b^(d/2)
Space b^d b^d bm bl bd b^(d/2)
Optimal? Yes Yes No No Yes Yes
Complete? Yes Yes No Yes if l≥d Yes Yes
34
Uninformed Search Strategies
(Case Study)
35
Case Study (1)
• Find the path from S to G by using BFS and DFS method
S
L
A K
C
B D
G
H E
J I F
36
Case Study (2)
• Simulate the node expansion from start state (S) to reach
goal state (G) by using Uniform Cost Search (UCS) algorithm
2.0 S 2.0
1.0 L
1.0
A K
C
2.0 1.0
B D
3.0
2.0 1.0
G
H E
1.0
2.0 5.0 1.0
J I F
1.0 37
References
• Stuart Russell, Peter Norvig,. 2010. Artificial intelligence : a modern
approach. PE. New Jersey. ISBN:9780132071482, Chapter 1 & 2
• Elaine Rich, Kevin Knight, Shivashankar B. Nair. 2010. Artificial
Intelligence. MHE. New York. , Chapter 1 & 2
• Uninformed Search Strategies:
http://artint.info/html/ArtInt_52.html
• Simple Implementation of Uninformed Search Strategies:
http://www.codeproject.com/Articles/203828/AI-Simple-Implemen
tation-of-Uninformed-Search-Stra
• UCS:
http://intelligence.worldofcomputing.net/ai-search/uniform-cost-sear
ch.html
» Widodo Budiharto, Derwin Suhartono. Artificial Intelligence:
Konsep dan Penerapannya. PT. Andi Yogyakarta, Indonesia. 2014.
ISBN: 978-979-29-4222-4. Chapter 2.
38