Chapter 3:
Informed Search and
Exploration
Dr. Daisy Tang
Informed Search
Definition:
Use problem-specific knowledge beyond the
definition of the problem itself
Can find solutions more efficiently
Best-first search
Greedy best-first search
A*
Heuristics
CS 420: Artificial Intelligence 2
Best-First Search
Idea: use an evaluation function f(n) for each node
estimate of "desirability"
Expand most desirable unexpanded node
Implementation: use a data structure that maintains the frontier in
a decreasing order of desirability
Is it really the best?
Special cases: uniform-cost (Dijkstra’s algorithm), greedy search,
A* search
A key component is a heuristic function h(n):
h(n) = estimated cost of the cheapest path from node n to a goal node
h(n) = 0 if n is the goal
h(n) could be general or problem-specific
CS 420: Artificial Intelligence 3
Best First Search Algorithm
1. initialize the Q with the starting state (node)
2. while Q is not empty, do
1) assign the first element of Q to N
2) if N is the goal, return SUCCESS
3) remove N from Q
4) add the children of N to Q
5) sort the entire Q by f (n)
3. return FAILURE
CS 420: Artificial Intelligence 4
Recall Romania Map Example
What’s a proper heuristic that measures cheapest path from current node to goal node?
CS 420: Artificial Intelligence 5
Romania Map with Costs
CS 420: Artificial Intelligence 6
Greedy Best-First Search
Evaluation function: f(n) = h(n)
estimate the cost from n to goal
hSLD = straight line distance from n to
Bucharest
CS 420: Artificial Intelligence 7
Example: Arad to Bucharest
CS 420: Artificial Intelligence 8
Example: Arad to Bucharest
CS 420: Artificial Intelligence 9
Example: Arad to Bucharest
CS 420: Artificial Intelligence 10
Example: Arad to Bucharest
CS 420: Artificial Intelligence 11
Analysis of Greedy Best-First
Complete?
From Iasi to Fagaras
No – can get stuck in loops, e.g., Iasi Neamt Iasi
Neamt …
Time?
O(bm), but a good heuristic can give dramatic
improvement
Space?
O(bm) -- keeps all nodes in memory
Optimal?
No
CS 420: Artificial Intelligence 12
A*: Minimizing Total Est. Cost
Idea: avoid expanding paths that are
already expensive
Evaluation function f (n) = g(n) + h(n)
g (n) = cost so far to reach n
h (n) = estimated cost from n to goal
f (n) = estimated total cost of path through n to
goal
CS 420: Artificial Intelligence 13
A* Search Example
CS 420: Artificial Intelligence 14
A* Search Example
CS 420: Artificial Intelligence 15
A* Search Example
CS 420: Artificial Intelligence 16
A* Search Example
CS 420: Artificial Intelligence 17
A* Search Example
CS 420: Artificial Intelligence 18
A* Search Example
CS 420: Artificial Intelligence 19
Exercise
Use A* graph-search to generate a path
from Lugoj to Bucharest using the straight-
line distance heuristic.
CS 420: Artificial Intelligence 20
Admissible Heuristic
A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach
the goal state from n
An admissible heuristic never overestimates the
cost to reach the goal, i.e., it is optimistic
Example: hSLD(n) (never overestimates the actual
road distance)
Theorem: If h(n) is admissible, A* using TREE-
SEARCH is optimal
CS 420: Artificial Intelligence 21
Optimality of A* -- Proof
Suppose some suboptimal goal G2 has been generated and is
in the fringe. Let n be an unexpanded node in the fringe
such that n is on a shortest path to an optimal goal G.
Assume the optimal cost is C*
f(G2) = g(G2) + h(G2) = g(G2) > C*
f(n) = g(n) + h(n) <= C*
from the above, we have
f(n) <= C* < f(G2)
thus G2 will not be expanded
CS 420: Artificial Intelligence 22
Case-Study
A* using Graph-Search returns a
suboptimal solution with an h(n) function
that is admissible.
CS 420: Artificial Intelligence 23
Consistency Heuristics
A heuristic is consistent if for every node n, every successor
n' of n generated by any action a, h(n) ≤ c(n,a,n') + h(n')
Triangle inequality
Every consistent heuristic is also admissible
Proof by induction on the number k of nodes
on the shortest path to any goal from n.
K = 1, let n’ be the goal node; then h(n) ≤ c(n, a, n’)
Assume n’ is on the shortest path k steps from the goal and that
h(n’) is admissible by hypothesis, then:
h(n) ≤ c(n,a,n’) + h(n’) ≤ c(n,a,n’) + h*(n’) = h*(n)
So, h(n) at k+1 steps from the goal is also admissible.
CS 420: Artificial Intelligence 24
A* With Graph Search
Theorem: If h(n) is consistent, A* using GRAPH-
SEARCH is optimal
If h is consistent, and n’ is a successor of n, we
have
f(n') = g(n') + h(n')
= g(n) + c(n,a,n') + h(n')
≥ g(n) + h(n)
= f(n)
i.e., f(n) is non-decreasing along any path
Whenever A* selects a node for expansion, the
optimal path to that node has been found
CS 420: Artificial Intelligence 25
Optimality of A*
A* expands nodes in order of increasing f value
Assume C* is the optimal cost
A* expands all nodes with f(n) < C*
A* might then expand some of the nodes right on the “goal contour”
(f(n) = C*) before selecting a goal node
Uniform-cost search (h(n) = 0) bands more circular
CS 420: Artificial Intelligence 26
Analysis of A*
Important idea:
appropriate h(n) function
A* is optimal efficient (no other optimal alg. is guaranteed to
expand fewer nodes than A*)
pruning while still guaranteeing optimality
Complete?
Yes (unless there are infinitely many nodes with f ≤ f(G))
Optimal?
Yes, with finite b and positive path cost
However, A* is not the answer for all problems
Time?
Exponential in the length of the solution
Space?
Keeps all nodes in memory
A* usually runs out of space long before it runs out of time
CS 420: Artificial Intelligence 27
Heuristic Functions
Two commonly used functions:
h1(n) = number of misplaced tiles
e.g., h1(n) = 8 in the above example
h2 (n) = sum of the distances of the tiles from their goal
positions, called Manhattan distance
e.g., h2 (n) = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18 in the
above example
CS 420: Artificial Intelligence 28
Quality of Heuristic
Assume # of nodes generated by A* for a problem
is N and the solution depth is d, then b* is the
effective branching factor that a uniform tree of
depth d would have to have. Thus:
N + 1 = 1 + b* + (b*)2 + … + (b*)d
b* might vary across problem instances, but is
fairly constant for sufficiently hard problems
A well-designed heuristic would have a value of b*
close to 1
CS 420: Artificial Intelligence 29
The Comparison
Each data point corresponds to 100 instances of the
8-puzzle problem in which the solution depth varies.
CS 420: Artificial Intelligence 30
Heuristics Domination
If h2(n) ≥ h1(n) for all n (both
admissible)
then h2 dominates h1
h2 is better for search
A* using h2 will never expand more
nodes than A* using h1
CS 420: Artificial Intelligence 31
Inventing Admissible Heuristic
A problem with fewer restrictions on the
actions is called a relaxed problem
The cost of an optimal solution to a relaxed
problem is an admissible heuristic for the
original problem
If the rules of the 8-puzzle are relaxed so that a
tile can move anywhere, then h1(n) gives the
shortest solution
If the rules are relaxed so that a tile can move
to any adjacent square, then h2 (n) gives the
shortest solution
CS 420: Artificial Intelligence 32
Inventing Admissible Heuristic
If a collection of admissible heuristics h1 …
hm is available, and none of them
dominates any of the others, we can choose
h (n) = max{h1(n), …, hm(n)}
We can also get from sub-problem of a
given problem
CS 420: Artificial Intelligence 33
Discussion
Project 1
CS 420: Artificial Intelligence 34
Exercise
The heuristic path algorithm is a best-first
search in which the objective function is
f(n) = (2-w) x g(n) + w x h(n). For what
values of w is the algorithm guaranteed to
be optimal? (You may assume that h is
admissible.) What kind of search does this
perform when w = 0? When w = 1? When
w = 2?
CS 420: Artificial Intelligence 35
Exercise
Prove each of the following statements:
Breadth-first search is a special case of uniform-
cost search.
Breadth-first search, depth-first search, and
uniform-cost search are special cases of best-
first search.
Uniform-cost search is a special case of A*
search.
CS 420: Artificial Intelligence 36