8 Min Read

Deconstructing the A* Search Algorithm: Heuristics, Admissibility, and Step-by-Step Exam Tracing

Published: October 2026 • Author: Sarthak Pawar

The A* Search Algorithm is the most important informed search algorithm in Artificial Intelligence and is examined in detail in ADPC201. It elegantly combines the guaranteed shortest-path property of Dijkstra's algorithm with the speed advantage of Greedy Best-First Search by using a heuristic function to guide the search toward the goal while keeping track of actual path costs. Understanding A* deeply—not just its pseudocode—will serve you well in every AI course you take in Third Year and beyond.

The Evaluation Function: f(n) = g(n) + h(n)

The core of A* is its evaluation function f(n) = g(n) + h(n), where:

  • g(n): The exact, accumulated cost of the path from the start node to the current node n. This is computed precisely as the algorithm runs — it is not estimated. g(n) ensures we track real costs and don't take unnecessarily expensive paths.
  • h(n): The heuristic estimate of the cost from node n to the goal. This is the key insight of A*: we use domain knowledge to estimate how close we are to the goal without fully exploring. Common heuristics: Manhattan distance for grid problems, Euclidean distance for geometric problems, 0 for Dijkstra (no heuristic).
  • f(n): The total estimated cost of the cheapest path through node n. A* always expands the node with the lowest f(n) value from the open list (priority queue).

Admissibility — Why the Heuristic Must Never Overestimate

For A* to be guaranteed to find the optimal (lowest-cost) path, the heuristic h(n) must be admissible: it must never overestimate the true remaining cost to reach the goal. Formally: h(n) ≤ h*(n) for all nodes n, where h*(n) is the true optimal cost from n to the goal.

Intuitively, if your heuristic overestimates, it makes certain paths look more expensive than they really are. A* might therefore skip the optimal path in favor of a path that appears cheaper according to the heuristic but is actually longer. An admissible heuristic, by always being optimistic (underestimating), ensures that A* never prematurely discards the optimal path.

Manhattan distance is admissible for grid problems because you can never travel fewer steps than the Manhattan distance requires. Euclidean distance is admissible for geometric problems because the straight-line distance is always the shortest possible distance between two points.

Python 3 A* Algorithm — Annotated Implementation
import heapq

def a_star(graph, start, goal, heuristic):
    # (f_score, node, path, g_cost)
    open_list = [(heuristic[start], start, [start], 0)]
    closed = {}  # node -> best g_cost seen so far

    while open_list:
        f, node, path, g = heapq.heappop(open_list)

        if node == goal:
            return path, g  # Found optimal path

        if node in closed and closed[node] <= g:
            continue  # Already found a better path to this node
        closed[node] = g

        for neighbor, edge_cost in graph.get(node, []):
            new_g = g + edge_cost
            new_f = new_g + heuristic.get(neighbor, 0)
            heapq.heappush(open_list,
                (new_f, neighbor, path + [neighbor], new_g))

    return None, float('inf')  # No path found

How to Trace A* in Your ETE Paper for Full Marks

When an exam question asks you to trace A* on a given graph, follow this exact format to earn every mark:

  • Step 1: Draw the graph clearly with all nodes and edge weights labeled.
  • Step 2: List the given heuristic values h(n) for each node next to the graph.
  • Step 3: Create a table with columns: Iteration | Node Expanded | g(n) | h(n) | f(n) | Open List (after expansion) | Closed List
  • Step 4: Fill the table row by row, always selecting the node with minimum f(n) from the Open List. Show tie-breaking explicitly.
  • Step 5: State the optimal path and total cost clearly at the end.
  • Bonus mark: Verify that the chosen path cost matches the sum of edge weights along the stated path.

🔗 Related Study Resources