CodeBlanks Logo Icon CodeBlanks

Algorithm properties

Learn finiteness, definiteness, input, output and effectiveness.

Finiteness and definiteness

Finiteness means the algorithm stops after a fixed number of steps. A procedure with an infinite loop is not an algorithm.

Definiteness means each step has a single interpretation. 'Stir a bit' is ambiguous; 'stir for 5 seconds' is definite.

Input, output and effectiveness

Input is the values given at the start; zero or more. Output is the result produced; at least one is required.

Effectiveness means each step is simple and doable. 'Find the infinite number' is not effective because it cannot be done in finite time.

Practice Square a number

Write square(n). Return n * n and print 36 with print(square(6)).

Starter code

solution.py
def square(n):
    # Square a number

Sample solution

solution.py
def square(n):
    # Square a number
    return n * n
print(square(6))

Expected output

36

Questions and answers

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

1 Effectiveness

Question
Each step must be doable in ____ time.
Answer
Each step must be doable in finite time.

Explanation: finite is right.

2 Algorithm properties: match the terms

Term Meaning
Finiteness Ends
Definiteness Unambiguous
Input Starting
Effectiveness Doable

3 How many outputs must an algorithm produce at minimum?

  • Zero
  • One Correct answer
  • Two
  • Infinite

Explanation: An algorithm produces at least one output.

All lessons in Beginner