Chapter 3
Chapter 3
Chapter 3
Solving Problems By
Searching
Chapter 3 S o l v i n g P r o b l e m s B y S e a r c h i n g
1
Outline
♦ Problem-solving
agents
♦ Example Problems
♦ Problem
formulation
♦ Search Algorithms
♦ Uninformed Search
Strategies
♦ Informed
(Heuristic) Search
Strategies
states??
actions??
goal
test??
path
cost??
Example: vacuum world state space graph
7 2 4 1 2 3
5 6 4 5 6
8 3 1 7 8
states??
actions??
goal
test??
path
cost??
Example: The 8-puzzle
7 2 4 1 2 3
5 6 4 5 6
8 3 1 7 8
Start State
Goal State
7 2 4 1 2 3
5 6 4 5 6
8 3 1 7 8
Start State
Goal State
7 2 4 1 2 3
5 6 4 5 6
8 3 1 7 8
Start State
Goal State
7 2 4 1 2 3
5 6 4 5 6
8 3 1 7 8
Start State
Goal State
Basic idea:
offline, simulated exploration of state
space
by generating successors of already-
explored states (a.k.a. expanding
states)
function Tree-Search( problem, strategy) returns a solution, or
failure initialize the search tree using the initial state of
problem
loop do
if there are no candidates for expansion then
return failure choose a leaf node for expansion
according to strategy
if the node contains a goal state then return the
corresponding solution
else expand the node and add the resulting nodes
to the search tree
end
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Tree Search
Sub Tree
Tree Search
Tree Search
Tree search example
Tree search example
Tree search example
Search strategies
Searching For Solutions
• A strategy is defined by picking the order of node
expansion
Measuring problem-solving performance
• Strategies are evaluated along the following
dimensions:
– Completeness: does it always find a solution if one exists?
– Optimality: does it always find a least-cost solution?
–
– Time complexity: number of nodes generated (basic
operation)
– Space complexity: maximum number of nodes in memory
• Time and space complexity are measured in terms
of
– b: maximum branching factor of the search tree
– d: depth of the least-cost solution
– m: maximum depth of the state space (may be ∞)
Types of Search strategies
• The disadvantage
• the space complexity (worst) and the time complexity are
enormous
Artificial Intelligence 61
Uniform Cost Search (UCS)
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
Goal 4 5
state
[x] = g(n) [7] [8]
path cost of
node n 64
Uniform Cost Search (UCS)
5 2
[5] [2]
65
Uniform Cost Search (UCS)
5 2
[5] [2]
1 7
[3] [9]
66
Uniform Cost Search (UCS)
5 2
[5] [2]
1 7
[3] [9]
4 5
[7] [8]
67
Uniform Cost Search (UCS)
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
4 5
[7] [8]
68
Uniform Cost Search (UCS)
5 2
[5] [2]
Goal state
1 4 1
path cost 7
g(n)=[6] [3] [9]
[9]
4 5
[7] [8]
69
Uniform Cost Search (UCS)
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
4 5
[7] [8]
70
Uniform Cost Search: Example3
H
F G
E
A
B C
D
Instructor:Ahmad M. AL-Smadi 71
Uniform Cost Search
H
F G
E
A
B C
D
Instructor:Ahmad M. AL-Smadi 72
Uniform Cost Search
Instructor:Ahmad M. AL-Smadi 73
Depth-first search
Stack
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Properties of Depth-first search
• Not complete
– because a path may be infinite or looping then the path will
never fail and go back try another option
• Not optimal (refer to the previous figure)
– depth- first search will explore the entire left subtree even if
node 14 is a goal node.
– hence, depth-first search is not optimal.
Artificial Intelligence 94
Properties of Depth-first search
Artificial Intelligence 96
Depth-limited search
Types:
Least
Value
A* Search Example 1
A* Search Example 1
A* Search Example 1
A* Search Example 2
A* Search Example 2
A* Search Example 2
A* Search Example 2
A* Search Example 2
A* Search Example 2
Summary