Computer science
Algorithms in everyday life
Precise sequences of steps: the idea behind every program, and behind every recipe.
When you cook from a recipe, follow directions, or brush your teeth in the morning, you are running an algorithm: a sequence of steps that reliably gets you to a goal. That exact idea sits inside every computer program. Here you will learn what makes a good sequence of steps and why computers are so picky about it.
What is an algorithm?
An algorithm is a precise sequence of steps that solves a problem. Three properties define it: every step is unambiguous, so there is nothing to guess. The sequence is finite, it ends at some point. And every step is executable, you can actually do it. A recipe with the step "season to taste" is fine for you, but it fails as an algorithm: it is not unambiguous.
Steps: 0
Why computers need exact instructions
A human understands "turn right up ahead" and fills in the rest. A computer cannot: it has no gut feeling and no common sense. It does exactly what is written, no more and no less. If a step is missing or unclear, the computer stops or does something wrong. That is why programmers break every problem into tiny, unambiguous steps.
Order matters
In an algorithm, order is crucial. Socks first, then shoes works. The other way around gets uncomfortable. When making tea: boil the water first, then pour. If you swap steps, you often get a completely different result, even though every single step is correct. Good algorithms therefore define not only what happens, but also when.
Exercises
0 of 6 solvedTime to try it yourself. You can't break anything, every attempt counts.
What is an algorithm?
Which instruction is unambiguous enough for a computer?
A robot starts on square 1 of a row and gets the commands: move 2 forward, move 3 forward. On which square does it end up?
Put the steps of a tea algorithm into a sensible order. The water takes the longest, so you heat it first.
- 1Let the tea steep for five minutes
- 2Take the teabag out
- 3Heat the water
- 4Pour the water into the cup
- 5Put the teabag in the empty cup
An algorithm says: start at 5. Double the number. Then subtract 4. What number comes out?
Complete the sentence: every step of a good algorithm must be ….
Where this leads