Finding and fixing a mistake in an algorithm

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Finding and fixing a mistake in an algorithm

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is a bug in an algorithm?
A A small insect on the computer
B A mistake in the steps
2. How do you find a bug in an algorithm?
A Follow the steps one by one until the result goes wrong
B Guess which step is wrong without following them
3. Making toast: 1. Eat the toast. 2. Put bread in the toaster. 3. Wait for it to pop up. What type of bug is this?
A Wrong order
B Missing step
4. Brushing teeth: 1. Wet the toothbrush. 2. Brush your teeth. 3. Rinse your mouth. The toothpaste never gets used. What type of bug is this?
A Wrong order
B Missing step
5. An algorithm says: 'Draw a line.' The robot does not know how long or in which direction. What type of bug is this?
A Unclear step
B Wrong order

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1bug AA bug: the steps are in the wrong order
21. Put on shoes 2. Put on socks BA mistake in an algorithm that makes the result go wrong
3To fix a missing step bug, add the step that was left out CWrong order: the milk is poured before there is a bowl. Move 'Get a bowl' to step 1.
4To fix an unclear step bug, make the step exact so anyone can follow it DMissing step: there is no step to wash with soap. Add 'Rub soap on your hands' after step 1.
51. Pour milk on cereal 2. Get a bowl 3. Eat the cereal EWalk 10 steps forward
61. Wet your hands 2. Rinse your hands 3. Dry your hands F1. Get bread 2. Add butter 3. Add cheese 4. Close sandwich

Definitions

bug

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
A mistake in an algorithm is called a ___
2.
1. Put on shoes 2. Put on socks Bug: step _ should come after step 2
3.
Bug: the step "Switch on kettle" is _______
4.
2. Add some sugar Bug: "some" is vague, so it is _______
5.
Follow the steps until the result goes wrong Then ___ that step

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A 1. Get a slice of bread
B 2. Eat the toast
C 3. Push the lever down
D 4. Wait for the toast to pop
Question 2
A 1. Tie your laces
B 2. Put on your shoes
C 3. Tie your laces
Question 3
A 1. Get a cup
B 2. Put a teabag in the cup
C 3. Pour in hot water
D 4. Wait for a while
Question 4
A 1. Fill the watering can
B 2. Carry it to the plant
C 3. Put the can away
Question 5
A SET total TO 0
B REPEAT 3 TIMES
C ADD some TO total
D SHOW total

Answer Key

Finding and fixing a mistake in an algorithm
Section A: Quick Questions
Q1
B — A mistake in the steps
Q2
A — Follow the steps one by one until the result goes wrong
Q3
A — Wrong order
Q4
B — Missing step
Q5
A — Unclear step
Section B: Match the Pairs
Q1
bug → A mistake in an algorithm that makes the result go wrong
Q2
1. Put on shoes 2. Put on socks → A bug: the steps are in the wrong order
Q3
To fix a missing step bug, add the step that was left out → 1. Get bread 2. Add butter 3. Add cheese 4. Close sandwich
Q4
To fix an unclear step bug, make the step exact so anyone can follow it → Walk 10 steps forward
Q5
1. Pour milk on cereal 2. Get a bowl 3. Eat the cereal → Wrong order: the milk is poured before there is a bowl. Move 'Get a bowl' to step 1.
Q6
1. Wet your hands 2. Rinse your hands 3. Dry your hands → Missing step: there is no step to wash with soap. Add 'Rub soap on your hands' after step 1.
Section C: Definitions
Q1
bug — A mistake in an algorithm. Follow the steps until the result goes wrong, then fix that step. It might be in the wrong order, missing, or unclear.
Section D: Fill in the Blanks
Q1
A mistake in an algorithm is called a bug
Q2
1. Put on shoes 2. Put on socks Bug: step 1 should come after step 2
Q3
Bug: the step "Switch on kettle" is missing
Q4
2. Add some sugar Bug: "some" is vague, so it is unclear
Q5
Follow the steps until the result goes wrong Then fix that step
Section E: Spot the Error
Q1
B — The steps are in the wrong order. You cannot eat the toast before it has been made. Step 2 should be 'Put bread in the toaster'.
Q2
A — The steps are in the wrong order. Laces cannot be tied before the shoes are on. Step 1 should be 'Put on your socks'.
Q3
D — This step is unclear. 'A while' does not say how long to wait, so different people would get different results. It should say 'Wait for three minutes'.
Q4
C — A step is missing. The plant never gets watered because the 'Tip water onto the soil' step was left out. Step 3 should be 'Tip water onto the soil'.
Q5
C — This step is unclear. 'some' is not a number, so the computer cannot add it. It should say 'ADD 2 TO total'.