AI Notes - Module 3
AI Notes - Module 3
In informed search, the search algorithm uses a heuristic function to estimate the cost or
distance from a given state to the goal. These heuristics guide the search towards the goal more
efficiently by selecting the most promising paths first.
The Euclidean Distance measures the straight-line (as-the-crow-flies) distance between two
points in space, such as between the current state and the goal state.
Formula:
Where:
Example:
To apply Euclidean distance in a more realistic context, let’s assume we are finding the straight-
line distance (as-the-crow-flies) between Belgaum and Panaji (Goa). The straight-line (or
Euclidean) distance is based on the geographical coordinates (latitude and longitude) of these
cities.
Where:
h(n) = 84.4 km
The Euclidean (straight-line) distance between Belgaum and Panaji (Goa) is approximately
84.4 kilometers. However, the actual driving distance will be longer (around 100-110 km)
since roads are not perfectly straight.
Key Property:
• This heuristic is admissible (it never overestimates) because it provides the shortest
straight-line path.
2. Manhattan Distance Heuristic
The Manhattan Distance measures the total distance traveled along grid lines (horizontal and
vertical paths only). This is often used in grid-based games or puzzles, such as when the agent can
only move up, down, left, or right.
Formula:
Use Case:
It’s used when movements are restricted to orthogonal directions (no diagonals), such as in
navigating through city blocks or in puzzles.
Example:
The Manhattan distance heuristic calculates how far each tile is from its correct position in terms
of horizontal and vertical moves only (like moving on a grid). It sums the individual distances of all
tiles from their goal positions.
2 8 3 1 2 3
1 6 4 4 5 6
7 5 7 8
Initial State Goal State
h(n)=1+1+0+2+2+1+0+2 = 9
Key Property:
• The Manhattan heuristic works well in grid environments but may underestimate in cases
where diagonal moves are allowed.
This heuristic counts the number of tiles not in their correct position in a puzzle, such as the 8-
puzzle or 15-puzzle. The fewer the misplaced tiles, the closer the state is to the goal.
Formula:
Use Case:
Used specifically for sliding-tile puzzles like the 8-puzzle, where tiles need to be arranged to match
a goal configuration.
Example:
Consider the following initial and goal states:
2 8 3 1 2 3
4 1 6 4 5 6
7 5 7 8
Key Property:
• This heuristic is admissible because it never overestimates the number of moves required
to reach the goal.
• g(n): The cost from the start node to the current node n.
• h(n): The heuristic estimate of the cost from n to the goal.
• f(n) = g(n) + h(n): The total estimated cost of the path through node n.
The A* algorithm explores the node with the lowest f(n) value, ensuring that it balances both the
actual cost from the start (g(n)) and the predicted cost to the goal (h(n)).
Advantages of A*:
• Optimal: It guarantees the shortest path if the heuristic is admissible (does not
overestimate the cost).
Disadvantages of A*:
• Memory-intensive: It stores all generated nodes, which can be a problem for large graphs.
• Performance depends on the heuristic: If the heuristic is not accurate, the algorithm’s
efficiency reduces.
The A algorithm* is an informed search technique that uses both the actual cost from the start node
to the current node (g(n)) and the estimated cost from the current node to the goal (h(n)). It selects
the path with the lowest f(n) = g(n) + h(n) at each step.
The heuristic function h(n) plays a crucial role in determining the efficiency and optimality of the A*
algorithm. The behavior of A* depends on whether the heuristic is overestimating or
underestimating the actual cost to the goal.
• Overestimation means that the heuristic value is greater than the actual cost from the
current node to the goal.
• This can lead the algorithm to believe a path is more promising than it actually is, which
might result in non-optimal solutions.
Effects of Overestimation:
1. Loss of Optimality: A* may no longer guarantee finding the shortest or least-cost path.
2. Faster but Incorrect: It may reach the goal faster but not via the best possible path.
3. Greedy-like behavior: Overestimation can make A* behave like Greedy Best-First Search
by focusing too much on the heuristic and ignoring the actual path cost.
Example of Overestimation:
Imagine in a route-finding problem, the actual remaining distance from a city to the goal is 100 km,
but the heuristic function predicts it to be 150 km. This overestimation might cause the algorithm to
explore paths that appear cheaper but are not optimal.
• Underestimation occurs when the heuristic predicts a cost less than the actual remaining
cost to the goal.
• While this makes A* more cautious, it ensures that the algorithm finds the optimal solution
because it explores all relevant paths.
Effects of Underestimation:
1. Optimal but Slow: A* will still guarantee the shortest or least-cost path but may explore more
nodes, leading to higher time complexity.
2. More Complete Search: The algorithm expands more nodes than necessary, increasing
computational overhead.
Example of Underestimation:
If the actual remaining cost from a city to the goal is 100 km, but the heuristic estimates it to be 50
km, A* will explore additional nodes unnecessarily to confirm the optimal path.
3. Greedy Best-First Search in AI:
Greedy Best-First Search (GBFS) is an informed search algorithm that focuses on expanding
the node that appears to be closest to the goal, according to a given heuristic function h(n). It tries
to reach the goal as fast as possible by selecting the node with the lowest heuristic value, but it
doesn’t consider the cost to reach the current node from the start (g(n)). Uses priority queue
method.
• Heuristic function h(n) estimates the cost from the current node to the goal.
• GBFS chooses the node with the smallest h(n) value from the open list (nodes waiting to
be explored).
• It focuses entirely on the goal, ignoring the cost of the path already traversed. This makes
it fast but prone to errors, as it can get stuck in local optima (suboptimal paths).
Analysis of GBFS:
Fast but not optimal: The search is goal-oriented and may not always find the shortest path. In this
example, it selected Karwar because of the lower heuristic value, but it ignored the actual cost (g(n))
to reach that node.
Advantages of Greedy Best-First Search:
1. Fast and simple: It selects the node that seems closest to the goal.
2. Useful for large state spaces: Focuses only on the goal, reducing the search space.
1. Not optimal: It may not find the shortest or most cost-effective path (local optimum issue).
2. Incomplete: It can get stuck in loops if the graph is not properly handled.
3. Heuristic-dependent: The efficiency heavily relies on the accuracy of the heuristic function.