What Are the 3 Requirements of an Algorithm?
The three requirements of an algorithm are finiteness, definiteness, and defined input and output. Finiteness means the steps end. Definiteness means each step has exactly one meaning. Input and output means the algorithm takes zero or more inputs and produces at least one output. Most textbooks extend this to five criteria by adding effectiveness and by counting input and output separately. That five-item list is the one to memorize for an exam.
The Five Criteria of an Algorithm
Donald Knuth set out the standard list in The Art of Computer Programming, and almost every data structures course repeats it.
| Criterion | What it requires | One-line test |
|---|---|---|
| Input | Zero or more values given before the steps begin | Can you name what goes in? |
| Output | At least one value that relates to the input | Can you name what comes out? |
| Definiteness | Every step is exact and has one meaning | Could two people follow it and act differently? |
| Finiteness | The steps end after a finite number of operations | Is there a valid input on which it never stops? |
| Effectiveness | Each step is basic enough to be done exactly, by hand, in finite time | Does any step say "somehow" or "guess"? |
The short answer of three comes from grouping input and output together and treating effectiveness as part of definiteness. The five-item version is the safer answer, because it covers both framings.
Finiteness
An algorithm must stop. A procedure that runs forever on some valid input is not an algorithm, even if every step is precise. The usual proof of finiteness is a quantity that gets smaller on every pass and cannot go below a bound. In a loop over a list of n items, the number of unvisited items falls by one each time and reaches zero after n steps.
Finiteness is a promise about every valid input, not the typical one. A search that stops when it finds the target still needs a rule for when the target is absent. Without that rule the procedure fails the criterion.
Definiteness
Each step must mean exactly one thing. "Pick a large number" is not definite. "Set max to the first element" is. Definiteness is what lets a computer, which cannot ask what you meant, carry out the steps. It is also why pseudocode uses fixed words such as if, for each, and return rather than free prose.
A related term is unambiguous. It means the same thing, and exam questions use the two words interchangeably.
Input and Output
An algorithm has zero or more inputs and at least one output. The zero is real: an algorithm that prints the first 100 primes takes no input. The at least one output is firm: a procedure that produces nothing observable has not solved anything. A common exam question asks "an algorithm must have at least ___". The answer is one output.
Input and output also fix the contract. Stating "input: a list of integers; output: the largest integer, or none if the list is empty" tells you what the algorithm is for before any step is written.
Effectiveness
Each step must be simple enough to be done exactly. Effectiveness is the criterion students most often skip. A step such as "find the shortest path" is definite in meaning but is not a basic operation. It has to be broken into steps that are. Knuth's test is whether a person with pencil and paper could carry out each step in finite time.
One Example Checked Against All Five
Here is a plain algorithm that finds the largest number in a list, followed by the check.
def find_max(numbers): if not numbers: return None largest = numbers[0] for value in numbers: if value > largest: largest = value return largest print(find_max([3, 9, 2, 7])) # 9 print(find_max([])) # None
- Input. One list of numbers, possibly empty.
- Output. The largest value, or None for an empty list. There is always exactly one output.
- Definiteness. Each line does one fixed thing: compare, assign, or return.
- Finiteness. The loop visits each of the n items once and then ends.
- Effectiveness. Comparing two numbers and copying a value are basic operations.
An algorithm that fails any one of these is not an algorithm. Being correct and being fast are separate questions asked after these five. The criteria only decide whether the procedure counts as an algorithm at all.
Key Takeaways
- The three requirements most often asked for are finiteness, definiteness, and defined input and output.
- The full list has five criteria: input, output, definiteness, finiteness, effectiveness. Give all five when a question allows it.
- An algorithm has zero or more inputs and at least one output.
- Finiteness must hold for every valid input, including the case where a search finds nothing.
- Apply these checks to real problems in Grokking the Coding Interview.
- Learn the structures the steps operate on in Grokking Data Structures for Coding Interviews.
- For recursive algorithms, where a missing base case is the usual finiteness mistake, see Grokking the Art of Recursion.

GET YOUR FREE
Coding Questions Catalog

$99

$197

$72