CURIUM
What do a recipe and a computer program have in common?

Algorithm

What do a recipe and a computer program have in common?

Both are algorithms: a finite, ordered sequence of instructions leading to a result. A recipe says to add, mix, and bake in order; a program adds, compares, and displays. Following the steps in the correct order is enough to get the dish, or the calculation you want.

MathsApplied mathematics

The three levels

Beginner

What do a recipe and a computer program have in common?

Both are algorithms: a finite, ordered sequence of instructions leading to a result. A recipe says to add, mix, and bake in order; a program adds, compares, and displays. Following the steps in the correct order is enough to get the dish, or the calculation you want.

Intermediate

What does a loop do in an algorithm?

To repeat instructions without rewriting them. To display numbers from 1 to 100, you do not write a hundred lines: a loop repeats 'display the number, then move to the next' until the count is reached. A loop is what makes an algorithm both short and powerful.

Expert

How can an algorithm make a choice while it runs?

Through a conditional test, in the form 'if... then... else'. The algorithm evaluates a condition — for example 'is this number even?' — then executes different instructions depending on whether it is true or false. This is what allows the same program to respond to different data.