UNIHIVE

Study Hub UNIPORT CSC 494

CSC 494 · Introduction to Artificial Intelligence

Informed (heuristic) search

Heuristic functions, greedy best-first search, A* search, admissibility and consistency, and local search.

Our notes

2 min read

Heuristics

A heuristic function h(n) estimates the cost from node n to the nearest goal, using knowledge of the problem. Examples:

  • Route finding: straight-line distance to the destination.
  • 8-puzzle: h₁ = number of misplaced tiles; h₂ = Manhattan distance (sum of each tile's horizontal and vertical distance from its goal square).

Greedy best-first search

Expands the node with the smallest h(n). Fast, but not optimal and not always complete: it can be lured down paths that look close but are expensive.

A* search

Expands the node with the smallest f(n) = g(n) + h(n): cost so far plus estimated cost to go.

  • Admissible h never overestimates the true cost: then A* (tree search) is optimal.
  • Consistent (monotone) h: h(n) ≤ cost(n, n′) + h(n′) for every step; then A* graph search is optimal and never needs to reopen nodes.

Worked example: A*

Edges (costs): S-A 1, S-B 4, A-B 2, A-G 10, B-G 3. Heuristic: h(S) = 5, h(A) = 4, h(B) = 3, h(G) = 0 (admissible: true costs to G are 6, 5, 3, 0).

  1. Expand S (f = 0 + 5 = 5). Add A (g 1, f 5) and B (g 4, f 7).
  2. Expand A (f 5). B via A: g 3, f 6 (better than 7, update). G via A: g 11, f 11.
  3. Expand B (f 6). G via B: g 6, f 6 (better than 11).
  4. Expand G (f 6): goal.

Path S-A-B-G, cost 6 (optimal; the direct A-G route costs 11).
Greedy search would expand S, then B (h 3 < 4), then G: path S-B-G cost 7, not optimal.

Comparing 8-puzzle heuristics

Both h₁ and h₂ are admissible; h₂ ≥ h₁ for every state (h₂ dominates h₁), so A* with h₂ expands fewer nodes.

Local search

For problems where only the final state matters (scheduling, 8-queens, timetable design):

  • Hill climbing: move to the best neighbour; can get stuck on local maxima and plateaus.
  • Simulated annealing: sometimes accepts worse moves, less often as "temperature" falls.
  • Genetic algorithms: a population of solutions with selection, crossover and mutation.

Exams usually ask

  • Define heuristic, admissible and consistent heuristics.
  • Trace A* (or greedy) on a graph and give the path and cost.
  • Compare greedy best-first search with A*.

Common mistake

Stopping A* as soon as the goal is generated. A* is optimal only if you stop when the goal is selected for expansion (removed from the frontier).

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All CSC 494 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.