Artificial Intelligence & Neural Networks β Problem Solving and Searching Techniques, NEC licence examination syllabus (Nepal Engineering Council).
Informed (Heuristic) Search
Using knowledge about the problem to look in the right direction β the largest win in search.
π Where this lives: when your phone plots a route across a country in milliseconds, it is not searching every road. A* with a straight-line-distance heuristic pulls the search toward the destination, and real routing engines add precomputed landmark distances that make the heuristic sharper still. The numbers in this topic show why: on the 15-puzzle, a good heuristic turns 3.6 million nodes into 1,641. No amount of faster hardware competes with that. Search "A* algorithm route planning heuristic landmarks".
Greedy best-first and A*
INFORMED (or HEURISTIC) SEARCH uses PROBLEM-SPECIFIC KNOWLEDGE
beyond the problem definition, so it can judge which non-goal
state looks more promising.
A HEURISTIC FUNCTION h(n) estimates the cost of the cheapest
path from the state at node n to a goal state.
h(n) β₯ 0, and h(n) = 0 for a goal node.
It is an ESTIMATE, supplied by the designer, and its quality
determines everything.
BEST-FIRST SEARCH is the general family: expand the node with
the best value of an EVALUATION FUNCTION f(n). The choice of f
gives the different algorithms.
GREEDY BEST-FIRST SEARCH
f(n) = h(n)
Expand the node that APPEARS CLOSEST TO THE GOAL.
Β· COMPLETE: no, in the tree-search version β it can get stuck
in a loop. The graph-search version is complete in a finite
space.
Β· OPTIMAL: NO. It follows the locally most promising route and
never reconsiders the cost already incurred.
Β· TIME and SPACE: O(b^m) in the worst case, though a good
heuristic reduces this substantially.
THE FAILURE MODE, and it is instructive: greedy search ignores
g(n) entirely, so it will happily take a step that looks like
progress toward the goal even when it has already travelled an
enormous distance. Going to Iasi to reach Fagaras, the classic
Romania example, sends the search to Neamt because Neamt looks
closer β and Neamt is a dead end.
A* SEARCH β the central algorithm of this topic
f(n) = g(n) + h(n)
where g(n) is the cost to reach n and h(n) the estimated cost
from n to the goal. So f(n) is the ESTIMATED COST OF THE
CHEAPEST SOLUTION THROUGH n.
Β· Identical to uniform-cost search except for the added h.
UCS is A* with h = 0.
Β· COMPLETE and OPTIMAL, provided the heuristic satisfies the
conditions below.
THE TWO CONDITIONS β this is the most examined content in the
topic:
ADMISSIBILITY
h(n) NEVER OVERESTIMATES the true cost to reach the goal:
h(n) β€ h*(n) where h* is the true optimal cost
An admissible heuristic is OPTIMISTIC.
WHY IT MATTERS: if h overestimates, A* may reject the
optimal path because it looks too expensive, and return a
worse one. ADMISSIBILITY GUARANTEES OPTIMALITY FOR
TREE-SEARCH A*.
CONSISTENCY (also called MONOTONICITY)
For every node n and every successor nβ² generated by action
a:
h(n) β€ c(n, a, nβ²) + h(nβ²)
This is a form of the TRIANGLE INEQUALITY: going via nβ²
cannot make the estimate cheaper than the direct estimate.
WHY IT MATTERS: consistency guarantees optimality for
GRAPH-SEARCH A* β the version with an explored set. With a
merely admissible but inconsistent heuristic, graph search
can close a node at a suboptimal cost and never revisit it.
EVERY CONSISTENT HEURISTIC IS ADMISSIBLE, but not the
reverse. In practice almost every natural admissible
heuristic is also consistent.
A KEY CONSEQUENCE OF CONSISTENCY: f(n) is NON-DECREASING along
any path, so A* expands nodes in order of non-decreasing f. It
therefore expands CONTOURS of equal f, like uniform-cost search
expanding circles of equal g β but the contours are stretched
toward the goal. THE BETTER THE HEURISTIC, THE MORE ELONGATED
THE CONTOURS AND THE NARROWER THE SEARCH.
OPTIMAL EFFICIENCY: A* is OPTIMALLY EFFICIENT among optimal
algorithms using the same heuristic β no other such algorithm
expands fewer nodes. That is a strong theoretical result, and
it means improvements must come from a better heuristic rather
than a cleverer algorithm.
THE REMAINING PROBLEM: A* KEEPS EVERY GENERATED NODE IN MEMORY.
It usually runs out of space long before it runs out of time β
the same wall as BFS in the previous topic β which is why the
memory-bounded variants below exist.
Heuristic quality, measured
TWO HEURISTICS FOR THE 8-PUZZLE, and this comparison is the
standard worked example:
hβ = the number of MISPLACED TILES (Hamming distance)
hβ = the sum of MANHATTAN DISTANCES of the tiles from their
goal positions (also called the city-block distance)
BOTH ARE ADMISSIBLE:
hβ β every misplaced tile must move at least once, so hβ
never overestimates
hβ β each tile must move at least its Manhattan distance,
and moves are one tile at a time
WORKED on the state
7 2 4 goal: _ 1 2
5 _ 6 3 4 5
8 3 1 6 7 8
hβ: tiles 7,2,4,5,6,8,3,1 are all out of place β hβ = 8
hβ: tile 7 at (0,0) β goal (2,1): 2+1 = 3
tile 2 at (0,1) β goal (0,2): 0+1 = 1
tile 4 at (0,2) β goal (1,1): 1+1 = 2
tile 5 at (1,0) β goal (1,2): 0+2 = 2
tile 6 at (1,2) β goal (2,0): 1+2 = 3
tile 8 at (2,0) β goal (2,2): 0+2 = 2
tile 3 at (2,1) β goal (1,0): 1+1 = 2
tile 1 at (2,2) β goal (0,1): 2+1 = 3
hβ = 3+1+2+2+3+2+2+3 = 18
The true optimal solution for this state is 26 moves, so
both are admissible and hβ is far more informed.
DOMINANCE: if hβ(n) β₯ hβ(n) for every n, and both are
admissible, then hβ DOMINATES hβ and A* with hβ never expands
more nodes than with hβ. A DOMINATING HEURISTIC IS ALWAYS
PREFERABLE, provided it is not too expensive to compute.
THE MEASURED EFFECT β the standard published comparison,
averaged over random instances:
depth IDS nodes A*(hβ) A*(hβ)
βββββββββββββββββββββββββββββββββββββββββββββ
12 3,644,035 227 73
16 too many 39,135 1,641
24 too many too many unmanageable
(for hβ at 24 and beyond)
βββββββββββββββββββββββββββββββββββββββββββββ
AT DEPTH 12: iterative deepening generates 3.6 MILLION nodes
where A* with Manhattan distance generates 73 β a factor of
about FIFTY THOUSAND. At depth 16 the two heuristics differ
from each other by a factor of 24.
THIS IS THE SINGLE MOST IMPORTANT ARITHMETIC IN THE SEARCH
SECTION. A better algorithm within uninformed search bought
11% (IDS versus BFS in nodes) or a change of exponent
(bidirectional). A GOOD HEURISTIC BUYS FOUR ORDERS OF
MAGNITUDE.
MEASURING HEURISTIC QUALITY β the EFFECTIVE BRANCHING FACTOR b*:
if A* generates N nodes and the solution is at depth d, then
b* is the branching factor a uniform tree of depth d would
need to contain N+1 nodes:
N + 1 = 1 + b* + (b*)Β² + β¦ + (b*)^d
A WELL-DESIGNED HEURISTIC HAS b* CLOSE TO 1.
COMPUTED FROM THE TABLE ABOVE:
hβ at d = 12, N = 227 β b* = 1.42
hβ at d = 12, N = 73 β b* = 1.26
hβ at d = 16, N = 39,135 β b* = 1.84
hβ at d = 16, N = 1,641 β b* = 1.48
Compare the uninformed branching factor of about 2.8 for the
8-puzzle. b* is the standard way to compare heuristics
because it is roughly constant across problem sizes, which
raw node counts are not.
Inventing heuristics, and the memory-bounded variants
WHERE DO HEURISTICS COME FROM? Four systematic sources.
1. RELAXED PROBLEMS
The cost of an OPTIMAL SOLUTION TO A RELAXED PROBLEM β one
with fewer restrictions on the actions β is an admissible
heuristic for the original.
WHY IT IS ADMISSIBLE, and this is the elegant part: the
optimal solution to the original problem is also A solution
to the relaxed problem, so the relaxed optimum can only be
cheaper. ADMISSIBILITY IS AUTOMATIC.
APPLIED TO THE 8-PUZZLE:
rule: a tile moves from A to B if A is adjacent to B and B
is blank
relax "B is blank" β each tile moves to its goal
independently β hβ, Manhattan
relax both conditions β a tile can teleport anywhere β
hβ, misplaced tiles
SO BOTH STANDARD HEURISTICS ARE RELAXATIONS, and the
technique generates them mechanically rather than by
inspiration. Straight-line distance for route finding is the
same trick: relax the requirement to follow roads.
2. SUBPROBLEMS AND PATTERN DATABASES
The cost of solving a SUBPROBLEM β say, getting tiles 1β4
into place and ignoring the rest β is admissible for the
whole. Store the exact costs for every configuration of the
subproblem in a PATTERN DATABASE, computed once by backward
search from the goal, then look them up during search.
DISJOINT pattern databases, whose subproblems share no
tiles, can have their costs ADDED and remain admissible.
This is what makes optimal 15-puzzle and Rubik's cube
solving practical.
3. LEARNING FROM EXPERIENCE
Solve many instances, record features of each state and the
actual cost to the goal, and fit a predictor. Such a
heuristic is NOT guaranteed admissible, so optimality is
lost β a real trade-off rather than a free improvement.
4. COMBINING HEURISTICS
Given several admissible heuristics with none dominating,
take the MAXIMUM:
h(n) = max{ hβ(n), hβ(n), β¦, hβ(n) }
The maximum of admissible heuristics is admissible and
dominates each of them. (The SUM is not admissible in
general β only for disjoint subproblems.)
MEMORY-BOUNDED VARIANTS β because A*'s space use is the practical
limit:
ITERATIVE-DEEPENING A* (IDA*)
Iterative deepening with the cutoff on f rather than depth.
Each iteration's limit is the smallest f-cost exceeding the
previous limit.
β space O(bd) β linear, like IDS
β with real-valued costs, each iteration may add only one
new node, so the number of iterations explodes. Best on
problems with few distinct f values, such as unit-cost
puzzles.
RECURSIVE BEST-FIRST SEARCH (RBFS)
Linear space; keeps the f-value of the best alternative path
from any ancestor, and unwinds when the current path exceeds
it, remembering the best f found so that it can be revisited.
β suffers excessive node REGENERATION.
SMA* (SIMPLIFIED MEMORY-BOUNDED A*)
Uses all available memory, and when full DROPS THE WORST
LEAF (highest f), backing its value up to its parent so the
subtree can be regenerated if needed.
β complete if any solution is reachable within memory
β optimal if the optimal solution is reachable
β on hard problems it can spend all its time regenerating
dropped nodes β memory pressure converts into time cost
WEIGHTED A*
f(n) = g(n) + WΒ·h(n) with W > 1. Weights the heuristic more
heavily, so the search is more focused and faster, at the
price of optimality: the solution found is at most W times
the optimal cost. A BOUNDED-SUBOPTIMALITY GUARANTEE, which is
often exactly the right engineering trade β a route 10%
longer found 100Γ faster.
THE SUMMARY OF THE WHOLE TOPIC: A* is optimally efficient for a
given heuristic, so THE HEURISTIC IS WHERE THE ENGINEERING
EFFORT BELONGS. Relaxation gives admissible heuristics
mechanically; pattern databases give sharp ones; taking the
maximum combines them; and if optimality can be traded, weighted
A* buys speed with a stated bound.
The relaxation trick is the most useful practical idea here: the optimal cost of a relaxed problem is automatically an admissible heuristic, because the original problem's solution is also a solution to the relaxed one and so can only cost more. That turns heuristic design from inspiration into a procedure β drop a constraint and solve what remains.
π Go further: production routing engines go far beyond straight-line distance with contraction hierarchies and ALT (A*, landmarks, triangle inequality). The idea is to precompute distances from every node to a handful of well-chosen landmarks; the triangle inequality then yields a much tighter admissible lower bound than geometry alone. The preprocessing takes minutes on a continental road network and turns queries into microseconds β which is a general pattern worth internalising: spend offline time to sharpen the heuristic, because A*'s cost is dominated by heuristic quality. Search "contraction hierarchies ALT landmarks route planning".
π‘ Exam angle: define h(n), g(n) and f(n), and give the evaluation function of greedy best-first (f = h) and A* (f = g + h), noting that UCS is A* with h = 0. Define admissibility and consistency/monotonicity with their formulas, and state precisely which guarantees which optimality (admissible β tree search, consistent β graph search). Be ready to compute hβ (misplaced tiles) and hβ (Manhattan distance) on a given 8-puzzle state β this is a near-certain numerical question. Explain dominance, the effective branching factor, and how to invent heuristics by relaxation, subproblems/pattern databases, and taking the maximum of several. Name the memory-bounded variants: IDA*, RBFS, SMA*.
Syllabus points
Greedy best-first search
A* search (numerical)
Hill climbing
Simulated annealing
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Related topics in Problem Solving and Searching Techniques