The big idea
An algorithm is a list of steps that tells someone exactly how to do a job. A recipe is an algorithm. So are the instructions for building a toy.
Computers cannot guess what you mean. They do exactly what they are told, one step at a time. So the steps must be clear, and they must be in the right order.
Let's explore
The order of the steps is called the sequence. Think about making a jam sandwich:
- Take two slices of bread.
- Spread jam on one slice.
- Put the other slice on top.
Now swap the steps around. "Put the other slice on top" first, then "spread jam". The jam ends up on the outside! The steps are the same, but the sequence is wrong, so the result is wrong.
Steps also need to be precise, which means exact. "Spread jam" is fine for a person. A robot might ask: how much jam? With what? On which side?
When we write an algorithm in a language a computer understands, it becomes a program. In tools like Scratch, you build programs by snapping blocks together in order.
Try it yourself
A robot sits on square 1 of a row of 5 squares, facing a cookie on square 4. Write an algorithm to get it to the cookie.
- Step 1: Move forward 1 square. (Now on square 2.)
- Step 2: Move forward 1 square. (Now on square 3.)
- Step 3: Move forward 1 square. (Now on square 4.)
- Step 4: Pick up the cookie.
Answer: 3 moves forward, then pick up. If you wrote "pick up" first, the robot grabs at an empty square!