5-Heuristic Search Greedy Search-08!01!2025
5-Heuristic Search Greedy Search-08!01!2025
The green numbers are the actual costs and the red numbers
are the heuristic value.
Best-first search
• Idea: use an evaluation function f(n) for each node
– estimate of "desirability"
Expand most desirable unexpanded node
• Implementation:
Order the nodes in fringe in decreasing order of desirability.
• Special cases:
– greedy best-first search
– A* search
Greedy best-first search
• Greedy best-first search algorithm always selects the
path which appears best at that moment.
• Evaluation function f(n) = h(n) (heuristic)
= estimate of cost from n to goal
• e.g., hSLD(n) = straight-line distance from n to
Bucharest
• Greedy best-first search expands the node that
appears to be closest to goal.
• The greedy best first algorithm is implemented by the
priority queue.
• Greedy best-first search expands nodes with minimal h(n). It is not optimal,
but is often efficient.
• It builds up a solution step by step, always choosing the next step that offers
the most obvious and immediate benefit. So the problems where choosing
locally optimal also leads to the global solution is the best fit for Greedy. In
this algorithm, the decisions are final, and not revised.
Romania with step costs in km
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Properties of greedy best-first search
• Optimal? No
Difference between uniform-cost search and
best-first search methods
– It has main loop that repeatedly gets the node, call it n with lowest f(n) value
from OPEN list.
– If n is goal node then stop (done) otherwise, n is removed from OPEN list &
added to the CLOSED list.
– Next all the possible successor nodes of n are generated.
– Similarly, if n is already in the OPEN list & the copy there has an equal or
lower f estimate, we can discard the newly generated n and move on.
Romania with step costs in km
A* search example
A* search example
A* search example
A* search example
A* search example
A* search example
Example – A* Search
h(n)
g(n)
f(n) = g(n)+h(n)
Source = S; Destination = G
Example – A* Search
Example – A* Search
Example – A* Search
Example – A* Search
Example – A* Search
Example – A* Search
Example – A* Search
17
Example – A* Search
Example – A* Search
17
Example – A* Search
17
Example – A* Search
Solution = SBEFG
A* Properties
• Admissible
• Optimality
• Consistent
Admissible heuristics
• 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.
• If h is consistent, we have
• Time? Exponential
• Optimal? Yes
Admissible heuristics
E.g., for the 8-puzzle:
• h1(S) = ?
• h2(S) = ?
Admissible heuristics
E.g., for the 8-puzzle:
Dominance
If h2(n) ≥ h1(n) for all n (both
admissible)
then h2 dominates h1
h2 is better for search
• h1(S) = ? 8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
Comparison between Uninformed vs Informed
Classical Search Method:
Uninformed/Informed
Uninformed/Informed
Uninformed/Informed method suitable
method not suitable for
for Observable, Deterministic, Known
Non-Observable, Non-
environments where the solution is a
Deterministic, Unknown
sequence of actions.
environments.