Heuristic
A heuristic is a "rule of thumb," or a practical shortcut for making decisions. In computer science, a heuristic is a technique an algorithm uses to find a "good enough" solution when the perfect one would take too long to compute.
Some real-world problems have so many possible solutions that checking every one is impractical, even for the fastest computers. A heuristic narrows the search by focusing on a reduced set of possible options, generated by a set of guidelines.
For example, shipping software needs to figure out how to pack items of different sizes into as few shipping boxes as possible. Instead of checking every possible combination, a simple heuristic like "pack the largest items first, then fill the gaps with smaller ones" produces a helpful result almost instantly. Online retailers like Amazon.com rely on heuristics like this every day.
Common uses of heuristics
- Pathfinding algorithms determine which paths to explore first. Video games and mapping apps use this to find routes quickly.
- Antivirus software uses heuristic analysis to spots malware by looking for suspicious behavior, such as a program trying to change system files or encrypt many documents.
- Video game AI, such as chess engines, can't analyze every possible move, so they use heuristics to judge which positions look strong.
- Compilers use heuristics to decide how to optimize code during compilation, such as when to inline a function.
- User interface designers often evaluate software using "usability heuristics," such as keeping the user interface consistent and providing clear feedback.
In computing, heuristics may trade some accuracy or certainty for speed. When an exact answer is too expensive to compute (in time or tokens), a good heuristic can produce a useful result in a reasonable amount of time.
Test Your Knowledge