Artificial Intelligence
Chapter 2
Search Spaces
◼ Search Trees
◼ Root node has no predecessor. (starting point)
◼ Leaf nodes have no successors.
◼ Goal nodes (of which there may be more
than one) represent solutions to a problem.
◼ Note that :
A path that leads from the root node to a goal node is called a
complete path. A path that leads from the root node to a leaf
node that is not a goal node is called a partial path.
3
Search Trees: An Example
◼ A is the root
node.
◼ L is the goal
node.
H, I, J, K, M, N and O are leaf nodes.
There is only one complete path:
A, C, F, L 4
Problem Solving by Searching
✓ Search: process of constructing sequences of actions
that achieve a goal given a problem.
✓ It is assumed that the environment is observable,
deterministic, static and completely known.
✓ Goal formulation is the first step in solving problems by
searching. It facilitates problem formulation.
✓ Formulating a problem requires specifying five
components: State representation, Initial state, Goal
state, Operators (actions), and Path cost function.
5
Problem solution
◼ A solution in the state space is a path from
the initial state to a goal state or, sometimes,
just a goal state.
• Path/solution cost: function that assigns a
numeric cost to each path, the cost of
applying the operators to the states
◼ Solution quality is measured by the path cost
function, and an optimal solution has the
lowest path cost among all solutions.
◼ Solutions: any, an optimal one, all. Cost is
important depending on the problem and the
type of solution sought.
Example: Romania
◼ Map searching (navigation)
7
Romania
◼ What’s the problem?
◼ Accomplish a goal
• Reach Bucharest by 13:00
• So this is a goal-based problem
Romania
◼ What’s an example of a non-goal-based
problem?
◼ Live long and prosper
◼ Maximize the happiness of your trip to
Romania
◼ Don’t get hurt too much
Search strategies
◼ A search strategy is defined by picking the order of node
expansion
◼ Strategies are evaluated along the following dimensions:
◼ Completeness: is the strategy guaranteed to find a solution when
there is one?
◼ Time complexity: number of nodes generated (how long does it take
to find a solution? )
◼ Space complexity: maximum number of nodes in memory (How
much space is used by the algorithm?)
◼ Optimality: If a solution is found, is it guaranteed to be an optimal
one? That is, is it the one with minimum cost?
◼ Time and space complexity are measured in terms of
◼ b: maximum branching factor of the search tree
◼ d: depth of the least-cost solution (the depth of the shallowest goal
node)
◼ m: maximum depth of the state space (may be ∞) (the maximum
length of any path in the state space)
Question
Uninformed vs. informed search
◼ Uninformed search
◼ no information about the number of steps
◼ or the path cost from the current state to the
goal
◼ search the state space blindly
◼ Informed search, or heuristic search
◼ a cleverer strategy that searches toward the
goal,
◼ based on the information from the current
state so far
◼ Informed search methods: Hill climbing, best-
first, greedy search, beam search, A, A*
Uninformed search
◼ Uninformed search strategies use only the
information available in the problem
definition
◼ Breadth-first search
◼ Uniform-cost search
◼ Depth-first search
◼ Depth-limited search
◼ Iterative deepening search
Breadth-first search
◼ The root node is expanded first (FIFO)
◼ All the nodes generated by the root
node are then expanded
◼ And then their successors and so on
Breadth-first search
S
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
Properties of breadth-first search
◼ Complete? Yes (if b is finite)
◼ Time? 1+b+b2+b3+… +bd + b(bd-1) = O(bd+1)
◼ Space? O(bd+1) (keeps every node in memory)
◼ Optimal? Yes (if cost = 1 per step)
◼ Space is the bigger problem (more than time)
◼ it can easily generate nodes at 10 MB/s, so 24 hrs
= 860GB!
Example
S
3 1 8
A B C
3 15
7 20 5
D E G
Breadth-First Search
Expanded node Nodes list
{ S0 }
S0 { A3 B1 C8 }
A3 { B1 C8 D6 E10 G18 }
B1 { C8 D6 E10 G18 G21 }
C8 { D6 E10 G18 G21 G13 }
D6 { E10 G18 G21 G13 }
E10 { G18 G21 G13 }
G18 { G21 G13 }
Solution path found is S A G , cost 18
Number of nodes expanded (including goal node) =
7
Example
◼ Consider the search graph below, where S is the start node and G1, G2,
and G3 are goal states. Arcs are labeled with the cost of traversing them
and the heuristic cost to a goal is shown inside the nodes. For each of
the three search strategies below, indicate which of the goal states is
reached:
Breadth-first search. Goal reached: ?
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
◼ Equivalent to breadth-first if step costs all equal
◼ Complete? Yes, if step cost ≥ ε
◼ Time? # of nodes with g ≤ cost of optimal solution,
O(bceiling(C*/ ε)) where C* is the cost of the optimal solution
◼ Space? # of nodes with g ≤ cost of optimal solution,
O(bceiling(C*/ ε))
◼ Optimal? Yes – nodes expanded in increasing order of g(n)
Uniform-Cost Search
Expanded node Nodes list
{ S0 }
S0 { B1 A3 C8 }
B1 { A3 C8 G21 }
A3 { D6 C8 E10 G18 G21 }
D6 { C8 E10 G18 G1 }
C8 { E10 G13 G18 G21 }
E10 { G13 G18 G21 }
G13 { G18 G21 }
Solution path found is S C G, cost 13
Number of nodes expanded (including goal node) = 7
Example
◼ Consider the search graph below, where S is the start node and G1, G2,
and G3 are goal states. Arcs are labeled with the cost of traversing them
and the heuristic cost to a goal is shown inside the nodes. For each of
the three search strategies below, indicate which of the goal states is
reached: 6
Uniform cost search. Goal reached:?
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
◼ Expand deepest unexpanded node
◼ Implementation:
◼ fringe = LIFO queue, i.e., put successors at front
Depth-first search
S
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
Depth-first search (Analysis)
◼ Not complete
◼ because a path may be infinite or looping
◼ then the path will never fail and go back
try another option
◼ Not optimal
◼ it doesn't guarantee the best solution
◼ It overcomes
◼ the time and space complexities
Properties of depth-first search
◼ Complete? No: fails in infinite-depth spaces, spaces
with loops
◼ Modify to avoid repeated states along path
→ complete in finite spaces
◼ Time? O(bm)
◼ Space? O(bm), i.e., linear space!
◼ Optimal? No
Depth-First Search
Expanded node Nodes list
{ S0 }
S0 { A3 B1 C8 }
A3 { D6 E10 G18 B1 C8 }
D6 { E10 G18 B1 C8 }
E10 { G18 B1 C8 }
G18 { B1 C8 }
Solution path found is S A G, cost 18
Number of nodes expanded (including goal node) = 5
Q
◼ For a general search problem, state which of
breadth-first search (BFS) or depth-first
search (DFS) is preferred under which of the
following conditions:
◼ 1. A shallow solution (path from initial state
to goal state) is preferred.
◼ 2. The search tree may contain large or
possibly infinite branches.
◼ 3. Very large memory space to store the
search tree (or the queue) is available.
Depth-Limited Strategy
◼ Depth-first with depth cutoff k (maximal
depth below which nodes are not expanded)
◼ Three possible outcomes:
◼ Solution
◼ Failure (no solution)
◼ Cutoff (no solution within cutoff)
Depth-limited search
◼ It is depth-first search
◼ with a predefined maximum depth
◼ However, it is usually not easy to define
the suitable maximum depth
◼ too small → no solution can be found
◼ too large → the same problems are
suffered from
◼ Anyway the search is
◼ complete
◼ but still not optimal
Depth-limited search
S depth = 3
A D 3
6
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
Iterative deepening search
◼ No choosing of the best depth limit
◼ It tries all possible depth limits:
◼ first 0, then 1, 2, and so on
◼ combines the benefits of depth-first and
breadth-first search
Iterative deepening search
Properties of iterative deepening
search
◼ Complete? Yes
◼
◼ Time? (d+1)b0 + d b1 + (d-1)b2 + … + bd =
O(bd)
◼
◼ Space? O(bd)
◼
◼ Optimal? Yes, if step cost = 1
Bidirectional search
◼ Run two simultaneous searches
◼ one forward from the initial state another
backward from the goal
◼ stop when the two searches meet
◼ However, computing backward is difficult
◼ A huge amount of goal states
◼ at the goal state, which actions are used to
compute it?
◼ can the actions be reversible to computer its
predecessors?
Bidirectional search
S
Forward
A D Backwards
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
Summary of algorithms