The short answer
A heuristic is a practical method for solving a problem. It is usually a rule of thumb, an estimate or a shortcut, and it aims to find a good answer quickly rather than a provably best one. In computer science, heuristics are used when exact methods would take too long.
Where the word comes from
“Heuristic” comes from the Greek heuriskein, meaning “to find” or “to discover.” It shares a root with the exclamation “eureka.” The mathematician George Pólya helped make the term widely known through his book How to Solve It (1945), which describes strategies for solving problems, such as asking what is unknown, what data is given and what the condition is.
Heuristics in computer science
In computer science, a heuristic is a technique that finds solutions faster when exact methods are too slow. It does this by trading some of the guarantees of an exact method, such as optimality, completeness, accuracy or precision, for speed. A heuristic is judged by whether its answer is good enough for the purpose, not by whether it is provably the best.
Examples
Greedy change-making
Suppose you need to give change using coins of several values. A greedy rule takes the largest coin that still fits, again and again. With US coins, this approach gives the fewest coins. With other coin sets, it can miss the fewest-coin answer, so it works as a heuristic in those cases.
Least recently used caches
A cache stores a small number of recently used items. When it is full, the least recently used rule removes the item that has gone longest without being used. This is a guess that recent use predicts future use. It is a heuristic, because the best possible rule would need to know future requests in advance.
Chess evaluation
A chess program cannot look ahead to the end of every game. Instead, it searches to a set depth and then scores the position using a heuristic evaluation, which weighs factors such as material and piece placement. The score is an estimate, not a proof of who is winning.
Distance estimates in search
A* search uses an estimate of the remaining distance to the goal to decide which path to explore next. If the estimate never overestimates the true distance, A* still finds a shortest path. The estimate is a heuristic that speeds up the search without changing the answer.
Heuristics in other fields
The term is used outside computer science in a few related ways:
- Psychology uses heuristics for mental rules of thumb, such as judging how likely something is by how easily examples come to mind.
- Usability design uses heuristic evaluation, in which reviewers check a user interface against a set of principles.
- Security software uses heuristic scanning to flag suspicious behavior that matches no known signature.
These uses share the basic idea of a practical shortcut, but the methods and standards differ from one field to the next.
Key takeaways
- A heuristic is a rule of thumb, estimate or shortcut that aims for a good answer quickly.
- The word comes from the Greek heuriskein, “to find” or “to discover.”
- In computing, heuristics are used when exact methods are too slow, and they often give up a guarantee of the best answer.
- Examples include greedy change-making, least recently used caches, chess evaluation and distance estimates in A* search.