CodeBlanks Logo Icon CodeBlanks

Algorithm definition

Learn that an algorithm is a finite sequence of steps turning input into output.

Algorithm definition

An algorithm is a finite sequence of steps taken to solve a problem. Every algorithm takes an input, processes the steps in order, and produces an output.

For example, a recipe, a route direction or a mathematical procedure is an algorithm. Steps must be definite and ordered.

Five core properties

An algorithm has five core properties: finiteness, definiteness, input, output and effectiveness.

These properties guarantee correct execution and let a machine run the algorithm without error.

Practice Write pseudocode

Write add(a, b). Return a + b and print 8 with print(add(3, 5)).

Starter code

solution.py
def add(a, b):
    # Add two numbers

Sample solution

solution.py
def add(a, b):
    # Add two numbers
    return a + b
print(add(3, 5))

Expected output

8

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which is an algorithm property?

  • Finiteness Correct answer
  • Infinity
  • Randomness
  • Ambiguity

Explanation: Finiteness is an algorithm property.

2 Algorithm output

Question
Every algorithm produces at least one ____.
Answer
Every algorithm produces at least one output.

Explanation: output is right.

3 Algorithm definition: match the terms

Term Meaning
Finiteness Ends
Input Starting
Output Result
Definiteness Unambiguous

All lessons in Beginner