- Computers and coding
- Classes 3-5
- 4 min read
Algorithms: instructions step by step
An algorithm is a list of clear steps in the right order. Learn to write, test and fix algorithms on paper.
Let us begin
The big idea
Every time you brush your teeth or make a glass of lemon water, you follow steps in an order. A list of steps that solves a job is called an algorithm. Computers need algorithms for everything they do.
An algorithm is a set of clear steps that must be followed in the right order to finish a job. A recipe is an algorithm. So is the way you get ready for school.
Order matters. If you put on your shoes before your socks, the job goes wrong. Each step must also be clear. A computer cannot guess what you mean, so we must say exactly what to do.
Sometimes an algorithm has a mistake. A mistake in the steps is called a bug. Finding and fixing it is called debugging. Test your steps by following them one by one, just like a computer would.
We can also write algorithms for a robot on a grid. We might say forward 2 or turn right. We use these small, exact commands to guide the robot to a square.
Worked examples
See how it works
Lemon water algorithm
Step 1: Pour water in a glass. Step 2: Squeeze a lemon into it. Step 3: Add some sugar. Step 4: Stir and drink. If we stir before we add the sugar, the sugar will not mix well, so order matters.
A robot on a grid
The robot stands on square (1,1) facing up. The first number is the column and the second is the row. Forward 2 moves it to (1,3). Turn right makes it face right. Forward 3 moves it to (4,3). So it stops at (4,3).
Finding the biggest number
Numbers: 7, 3, 9, 4. Say the biggest is 7. Look at 3. It is not bigger, so keep 7. Look at 9. It is bigger, so the biggest is now 9. Look at 4. It is not bigger. The biggest number is 9.
Try it at home
Be the human robot
You will need
- a cushion or a bag
- a friend or family member
- paper and pencil
What to do
- Put the cushion on the floor a few steps away from your friend.
- Write on paper a few commands: forward 1 step, turn left, turn right.
- Your friend closes their eyes and stands as the robot. You read the commands one at a time.
- Does the robot reach the cushion? If not, find the bug in your steps.
- Fix the steps and try again. Then swap places.
Ask a grown-up: An adult should check that the floor is clear so nobody trips or bumps into furniture.
Fun fact
The word algorithm comes from the name of a scholar from long ago, Al-Khwarizmi, who wrote about step-by-step methods for sums.
Practice sheet
Check what you learned
Practice sheet: Algorithms: instructions step by step (Classes 3-5, Computers and coding)
- What is an algorithm?
- Put in the right order: (a) wear shoes (b) wear socks (c) tie the laces.
- Why does the order of steps matter?
- A robot stands on (1,1) facing up. Each forward step moves it one square up. Where is it after forward 3?
- A robot stands on (1,1) facing up. It does forward 2, turn right, forward 1. Where does it stop? (Column first, then row.)
- Write an algorithm of four steps for drinking water from a bottle.
- This algorithm has a bug: 1. Eat the sandwich. 2. Spread butter on bread. 3. Take two slices of bread. What is wrong?
- Use the biggest-number method on 12, 5, 18, 9. Which is the biggest?
- Write simple steps to find the smaller of two numbers.
- A robot starts on (1,1) facing up. It does: forward 2, turn right, forward 3, turn right, forward 1. Where does it stop and which way does it face?
Answer key
Answers: Algorithms: instructions step by step
- A list of clear steps, in the right order, that solves a job.
- (b) wear socks, (a) wear shoes, (c) tie the laces.
- If the steps are in the wrong order the job goes wrong or cannot be done.
- (1,4).
- Forward 2 gives (1,3). Turn right makes it face right. Forward 1 gives (2,3). It stops at (2,3).
- Sample: 1. Pick up the bottle. 2. Open the cap. 3. Drink some water. 4. Close the cap.
- The steps are in the wrong order. The correct order is: take two slices of bread, spread butter, then eat the sandwich.
- 18.
- Sample: 1. Look at both numbers. 2. If the first is smaller, it is the answer. 3. If not, the second is the answer.
- Forward 2 gives (1,3). Turn right: facing right. Forward 3 gives (4,3). Turn right: facing down. Forward 1 gives (4,2). It stops at (4,2), facing down.
