Lecture 2
Solving Problems by
Searching
AI
Well-defined problems and solutions
A problem is defined by 5 components:
Initial state
Actions
Transition model or
(Successor functions)
Goal Test.
Path Cost.
Well-defined problems and solutions
A problem is defined by 4 components:
The initial state
that the agent starts in
The set of possible actions
Transition model: description of what each action
does.
(successor functions): refer to any state reachable from
given state by a single action
Initial state, actions and Transition model define the
state space
the set of all states reachable from the initial state by any
sequence of actions.
A path in the state space:
any sequence of states connected by a sequence of actions.
The 8-puzzle
The 8-puzzle
States:
a state description specifies the location of each of
the eight tiles and blank in one of the nine squares
Initial State:
Any state in state space
Successor function:
the blank moves Left, Right, Up, or Down
Goal test:
current state matches the goal configuration
Path cost:
each step costs 1, so the path cost is just the length
of the path
Searching For Solutions
Tree search example
Node selected
for expansion.
Nodes added to tree.
Selected for expansion.
Added to tree.
Note: Arad added (again) to tree!
(reachable from Sibiu)
Not necessarily a problem, but
in Graph-Search, we will avoid
this by maintaining an
“explored” list.
Uninformed Search Strategies
Uninformed strategies use only the
information available in the problem definition
Also known as blind searching
Breadth-first search
Depth-first search
Depth-limited search
Iterative deepening search
Uniform-cost search
10
Comparing Uninformed Search
Strategies
Completeness
Will a solution always be found if one exists?
Time
How long does it take to find the solution?
Often represented as the number of nodes searched
Space
How much memory is needed to perform the search?
Often represented as the maximum number of nodes stored
at once
Optimal
Will the optimal (least cost) solution be found?
11
Comparing Uninformed Search
Strategies
Time and space complexity are
measured in
b – maximum branching factor of the
search tree
d – depth of the least cost solution
m – maximum depth of the state space
Breadth-First Search
Recall from Data Structures the basic
algorithm for a breadth-first search on a
graph or tree
Expand the shallowest unexpanded node
Place all new successors at the end of a
FIFO queue
Breadth-First Search
Breadth-First Search
Breadth-First Search
Breadth-First Search
Properties of Breadth-First
Search
Complete
Yes if b (max branching factor) is finite
Time
1 + b + b2 + … + bd + b(bd-1) = O(bd+1)
exponential in d
Space
O(bd+1)
Keeps every node in memory
This is the big problem;
Optimal
Yes (if cost is 1 per step); not optimal in general
Depth-First Search
Recall from Data Structures the basic
algorithm for a depth-first search on a
graph or tree
Expand the deepest unexpanded node
Unexplored successors are placed on a
stack until fully explored
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
Complete
No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated spaces along path
Yes: in finite spaces
Time
O(bm)
Not great if m is much larger than d
But if the solutions are dense, this may be faster than
breadth-first search
Space
O(bm)…linear space
Optimal
No
Depth-First Search Graph --> Tree
a G
b c
e
d f
S h
p q r
d e p
b c e h r q
a a h r p q f
p q f q c G
q c G a
a
Iterative Deepening Search
Iterative deepening depth-first search
Uses depth-first search
Finds the best depth limit
Gradually increases the depth limit; 0, 1, 2, …
until a goal is found
Iterative Deepening Search
Iterative Deepening Search
Iterative Deepening Search
Iterative Deepening Search
Properties of iterative deepening search
Complete
Yes
Time
O(bd)
Space
O(bd)
Optimal
Yes if step cost = 1
Can be modified to explore uniform cost tree
Uniform cost search
Breadth-first finds the shallowest goal state
but not necessarily be the least-cost solution
work only if all step costs are equal
Uniform cost search
modifies breadth-first strategy
by always expanding the lowest-cost node
The lowest-cost node is measured by the path
cost g(n)
Uniform Cost Search
2 a G
Strategy: expand a b c
1 8
cheapest node first: 2 e 2 2
3 d f
Fringe is a priority 9
S h 8
queue (priority: 1
cumulative cost) 1p q r
15
S 0
d 3 e 9 p 1
b 4c e 5 h 1r 1 q 1
1 7 1 6
Cost a 6 a 1h 1 r 7 p q f
contou 3
rs p q f 8 q c G
q 1c G 1 a
1 0
a
End …