Algorithm

A set of instructions or rules used to solve a problem or perform a computation.

How should two equal-height books be shelved?

A small display needs a repeatable ordering rule. Imagine three books, Alder at 18 cm, Birch at 24 cm and Cedar at 18 cm. “Put the shortest first” leaves one decision open.

  1. Choose a key

    Use height, measured in the same units for every book. Decide what to do when a height is missing before sorting.

  2. Resolve a tie

    Sort by height ascending, then alphabetically by title within each height. Alder precedes Cedar even if Cedar was picked up first.

  3. Check the result

    The shelf reads Alder, Cedar, Birch. Every input book appears once, and the two shorter books are in the specified order.

What makes this an algorithm?

The inputs, rule and stopping condition are explicit enough for another person or program to reproduce the result. A fixed procedure can solve this task without being trained. Machine learning also relies on algorithms, including procedures that use examples to estimate parameters.

Books of different heights stand beside an ivory bookend.
Height alone leaves tied books in need of a second sorting rule.

Try changing one instruction

Sort titles in reverse order only within a tied height. Cedar moves ahead of Alder, while Birch stays last. This small test reveals exactly which part of the result depends on the second rule.

Follow the idea

ML (Machine Learning) · See where learning from examples enters a procedure.

Data Preprocessing · Follow rules that make inputs comparable.

Source · NIST Dictionary of Algorithms and Data Structures

Return to Algorithm in the A–Z glossary