= Algorithm
{wiki}
An algorithm is a finite, precise procedure for transforming an <input> into an <output>.
Here "finite" refers to the description: a short <algorithm> can perform arbitrarily many steps on increasingly large <inputs>. Solving a <computational problem> additionally requires termination and the specified <output> on every permitted <input>. State assumptions explicitly: <binary search> requires a <sorted array>.
An <algorithm> is an idea that can have implementations in different <programming languages>. Its explanation should make three things visible: the permitted <inputs>, the rule for each step, and the meaning of the returned <output>. <Algorithm correctness> then separates finding the right answer from eventually finishing; <time complexity> asks how much work finishing requires.
A particularly useful design question is: what knowledge survives each step? In <binary search>, it is the location of every possible match inside the remaining candidate range. Writing that fact as a <loop invariant> turns an intuitive shortcut into a procedure whose discarded candidates can be justified. This often helps discover the <algorithm>, rather than merely check it afterward.
Back to article page