An algorithm is simply a set of clear, step-by-step instructions for completing a task.
Think of it like a recipe for making a cake or the directions for building a LEGO model. The goal of this lesson is to demonstrate how important it is for those steps to be precise.
This lesson will include a hands-on activity that shows how computers follow instructions literally, and even a tiny mistake in the instructions can have an unexpected result.
Gather your pupils in a circle and place all the sandwich-making ingredients and tools (like a plate, knife, bread, butter and jam) in front of you. Tell them it's time to program their robot! Explain that they are the programmers, and you are the robot.
You have no common sense or prior knowledge about making a sandwich, so you can only follow their instructions exactly as they're given!
You should adopt a monotone voice and rigid movements to reinforce this persona.
Prompt the students for the very first instruction to make a sandwich. Follow their command literally, no matter how illogical it seems. For example:
If a student says, "Open the jar," try to pull the lid straight off.
If they say, "Put the bread on the plate," pick up the entire loaf of bread and place it on the plate.
If they say, "Spread the peanut butter," pick up the entire jar and try to smear it on the bread.
Continue to follow their instructions, exaggerating any mistakes to highlight why being clear and specific is so important.
After the first attempt, stop and discuss the results.
Ask the students: "What went wrong?" and "Why didn't my program work?" Explain that what they just did is called debuggingโthe process of finding and fixing mistakes in an algorithm.
Point out that the problem wasn't their idea, but the way they communicated the steps.
This shows them that a great idea needs a great, precise set of instructions.
Have the students work together to create a new, more precise set of instructions. Prompt them to think about every small detail, such as "pick up a single slice of bread" and "unscrew the lid from the jam jar."
You may want to write their new, clear algorithm on a whiteboard or a large piece of paper, writing each step on a new line to reinforce the sequential nature of code.