Heuristic Search

What are heuristics in AI?

Learn what heuristics are in AI: rules of thumb that estimate how close a state is to a goal, with simple examples and why they are not always perfect.

On this page
  1. A simple example
  2. Why heuristics help
  3. Why a heuristic is not always right
  4. Heuristics in other AI problems
  5. How heuristics differ from inference
  6. Where to go next

In AI, a heuristic is a rule of thumb or an estimate that helps a program reach a good answer without checking every possibility. In search problems, a heuristic is usually a function, written h(n), that estimates the cost of getting from a state n to a goal. The estimate is quick to compute, so a search can use it to decide which options to explore first.

A simple example

Suppose you want to drive across a city to a specific address. Checking every possible road in turn would take a long time. A useful rule of thumb is to prefer roads that lead in the direction of the destination. A numeric version of that rule is the straight-line distance from each intersection to the destination. The search looks at the options that seem closest to the goal first.

The estimate is not the same as the real route. A straight line ignores buildings, one-way streets and rivers, so it is only a guide.

Why heuristics help

  • They reduce the number of options a program has to check.
  • They focus the search on the options that look most promising.
  • They make it practical to search problems that are too large to check completely.

Why a heuristic is not always right

A heuristic is an estimate, so it can be wrong. A program that trusts a poor estimate may follow a route that looks good but is longer, or that leads nowhere. Some heuristics are designed so they never overestimate the true cost. This property is called admissibility, and it helps an algorithm such as A* find the best path. Other heuristics carry no such guarantee, but they can still be useful when a good answer is enough.

Heuristics in other AI problems

Heuristics are not limited to route finding:

  • Games. When a program cannot search all the way to the end of a game, it uses an evaluation function to score the positions it reaches.
  • Constraint problems. A common rule is to pick next the variable with the fewest legal values left. This is often called the minimum remaining values heuristic.
  • Planning. Estimates of how far a partial plan is from its goal can guide the search toward the most promising plans.

How heuristics differ from inference

Do not confuse heuristics with the types of inference in artificial intelligence. Inference describes how a system draws conclusions from facts it already knows. A heuristic is about which options to try first. The two often work together in the same system, but they answer different questions.

Where to go next

A heuristic is the building block of heuristic search, which uses these estimates to pick a method such as best-first search, A* or hill climbing. Once you know what a heuristic is, the overview of types of heuristic search in artificial intelligence shows how each method uses one.

The complete guide to heuristic search

Types of Heuristic Search in Artificial Intelligence
Read the guide

Keep exploring

Guides from other topics

All topics →