Module 3
Module 3
Definition Uses heuristics to guide the search Does not use any additional knowledge.
process.
Heuristic Utilizes a heuristic function h(n) to Does not have a heuristic; treats all
Function estimate the cost to the goal. nodes equally.
Space May require more memory due to storing Generally has lower memory
Complexity heuristic information and expanded requirements, depending on the
nodes. strategy used.
Use Cases Suitable for complex problems where Used in simpler problems or when no
heuristic information is available (e.g., heuristic information is available.
pathfinding, AI)
3.5.1 Greedy best-first search
• Greedy best first search tries to expand the node that is closest to the
goal, on the grounds that this is likely to lead to a solution quickly
• It evaluates nodes by sing just the heuristic function; i.e. f(n)=h(n)
• In route finding problems, straight line distance heuristic is used
normally being called as hSLD
• It can be well explained with route-finding problems in Romania
• From the table 3.22, hSLD (In(Arad)) = 366 it means straight line
distance from Arad to Bucharest is 366
• Notice that the values of hSLD cannot be computed from the problem
description itself. Moreover, it takes a certain amount of experience to
know that hSLD is correlated with actual road distances and is, therefore,
a useful heuristic.
Why it is called as greedy ?
• The greedy best-first search , for a given problem, using hSLD finds a
solution without ever expanding a node that is not on the solution
path; hence its search cost is minimal but it is not optimal.
• From the above problem we discussed, the path via Sibiu and Fagaras
to Bucharest is 32 km longer than the path through Rimnicu vilcea
and Pitesti. This shows why the algorithm is called greedy – at each
step it tries to get as close to the goal as it can
A* Search
• The most widely known form of best-first search is called A∗ search
• It evaluates nodes by combining g(n), the cost to reach the node, and h(n),
the cost to get from the node to the goal: f(n) = g(n) + h(n)
• Since g(n) gives the path cost from the start node to node n, and h(n) is the
estimated cost of the cheapest path from n to the goal,
• we have f(n) = estimated cost of the cheapest solution through n
• Thus, if we are trying to find the cheapest solution, a reasonable thing to try
first is the node with the lowest value of g(n) + h(n).
• It turns out that this strategy is more than just reasonable: provided that the
heuristic function h(n) satisfies certain conditions, A∗ search is both
complete and optimal.
• The algorithm is identical to UNIFORM-COST-SEARCH except that A∗ uses g
+ h instead of g.
• Before we start with actual concepts, lets have basics on some point
• Optimality means finding the best possible solution. In search
algorithms, this usually means finding the shortest path or the least
costly way to reach a goal
• A heuristic (a smart guess about the distance or cost to the goal) is
admissible if it never overestimates the actual cost to reach the goal
• Simple example: Imagine you are using a map to find the shortest route to a
city. An admissible guess about the distance would be something that’s equal
to or less than the real distance. For example, guessing the straight-line
distance between two cities is admissible because it will never be more than
the actual road distance (since roads are often longer than straight lines)
• Why it matters: If the algorithm only uses admissible guesses, it will
always find the best solution, or in other words, the optimal path
Consistency (also called Monotonicity)
• A heuristic is consistent if it not only never overestimates but also
guarantees that every step you take towards the goal doesn’t make
the guess worse
• Simple example: Let’s say you are walking from point A to point B, and your
guess about how much distance is left should not increase as you move closer
to B. In other words, every time you take a step towards the goal, your guess
should decrease in a way that makes sense
• Why it matters: If the heuristic is consistent, the algorithm becomes
more efficient because it won’t need to recheck paths it has already
considered. It ensures that as you move through the search space,
you are always moving in a sensible way towards the goa
Conditions for optimality: Admissibility and consistency
• The first condition we require for optimality is that h(n ) be an
admissible heuristic
• An admissible heuristic is one that never overestimates the cost to
reach the goal.
• Because g(n) is the actual cost to reach n along the current path, and
f(n)=g(n) + h(n), we have as an immediate consequence that f(n)
never overestimates the true cost of a solution along the current path
through n.
• Admissible heuristics are by nature optimistic because they think the
cost of solving the problem is less than it actually is.
• An obvious example of an admissible heuristic is the straight-line
distance hSLD that we used in getting to Bucharest
• Straight-line distance is admissible because the shortest path
between any two points is a straight line, so the straight line cannot
be an overestimate
• A heuristic h(n) is consistent if, for every node n and every successor
n’ of n generated by any action a, the estimated cost of reaching the
goal from n is no greater than the step cost of getting to n’ plus the
estimated cost of reaching the goal from n’