🧁 Algorithms: Recipes and Directions

3rd Grade 💻 Coding

Before you even touch a computer, you can learn the most important idea in programming with a cake, a map and two friends. That idea is called an algorithm — a list of exact steps that solves a problem. In this lesson we discover that you use algorithms every single day, and we practice writing a good one.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

What an algorithm is

An algorithm is a series of clear steps, in a set order, that takes you from the start to the result. A cake recipe is an algorithm: preheat the oven, mix the eggs and sugar, add the flour, pour it into the pan and bake for 30 minutes. The way from your house to school is an algorithm too: walk out the door, turn right, walk to the traffic light, cross at the crosswalk and turn left.

The word “algorithm” comes from the name of a Persian mathematician, Muhammad al-Khwarizmi, who lived in Baghdad more than a thousand years ago and wrote books about ways to work out calculations step by step. When his books were translated into Latin, his name turned into a word. Today algorithms are everywhere: in the calculator, in the map app on your phone and in the washing machine.

Game: the Robot and the Programmer

Try this game in pairs. One person is the “programmer” and the other is the “robot.” The goal: get the robot from one side of the room to a chair on the other side. The robot understands only four commands: “step forward,” “turn right,” “turn left” and “sit.” It doesn’t understand “go over there” or “walk around the table.” The programmer writes the list of commands on a sheet of paper, and only then does the robot carry it out — exactly, without fixing anything on its own.

You quickly find out how easy it is to make a mistake: forget one turn and the robot walks straight into the wall. Count five steps instead of six and it sits down on the floor. That’s exactly what happens to programmers: the computer, like the robot, does what’s written, not what you meant. You fix the list and try again — and that’s already your first peek at finding bugs.

What makes a good algorithm

A good algorithm has a few qualities. It’s precise: “add a little sugar” isn’t good enough for a computer — you need “add one cup of sugar.” It’s in order: you can’t bake before you mix. It finishes: after a certain number of steps you reach the result instead of going on forever. And it works every time — whoever follows it tomorrow will get the same cake.

Often there are several algorithms that reach the same result. You can get to school by different routes, and you can put cards in order using different methods. Programmers choose the fastest, simplest or safest algorithm for the problem. To plan, they sometimes write the steps in plain English on numbered lines — that’s called pseudocode — or draw a flowchart with boxes and arrows.

Algorithms all around us

Look around and you’ll find algorithms everywhere: the assembly instructions for a bookcase, the rules of a board game, the steps for brushing your teeth, and even the way a librarian puts books in alphabetical order. A traffic light is a simple algorithm that repeats itself: green, yellow, red, and back to the start.

When a programmer writes software, she first thinks about the algorithm — what the steps are — and only then writes them in a programming language. That’s why you can be very good at algorithmic thinking before you know a single language. Try it at home: write an algorithm for making a sandwich, and have someone follow it exactly as you wrote it. You’ll be surprised how many details you left out.

Key facts

  • An algorithm is a series of exact steps, in a set order, that leads to a result.
  • The word algorithm comes from the name of the mathematician al-Khwarizmi, who lived in Baghdad more than a thousand years ago.
  • A good algorithm is precise, in order, finishes and gives the same result every time.
  • Pseudocode is writing the steps in plain language before writing code.
  • The same problem can usually be solved with several different algorithms.

Quick quiz

  1. What is an algorithm?

  2. Which of these is an algorithm?

  3. Whose name does the word algorithm come from?

  4. Why is “add a little sugar” a bad instruction for a computer?

  5. In the Robot and the Programmer game, what happens if you forget a turn?

  6. What is pseudocode?

  7. Which quality is important for a good algorithm?

  8. Is there only one algorithm for every problem?

💭 Think and talk about it

  1. Write an algorithm for brushing your teeth. How many steps did you end up with?
  2. Why is it important for an algorithm to finish? What would happen if a recipe never ended?
  3. Think of two different ways to get from home to school. Which one is “better,” and why?

Questions kids ask

What’s the difference between an algorithm and a program?

An algorithm is the idea — the list of steps. A program is the algorithm written in a programming language so a computer can carry it out. The same algorithm can be written in many different languages.

How do you teach algorithms without a computer?

With games: the Robot and the Programmer, writing a recipe that someone else follows exactly, giving directions on a map, or putting cards in order. This is called “unplugged” learning — no electricity needed.

Does artificial intelligence use algorithms too?

Yes. AI systems are built from algorithms that teach them to find patterns in examples.

🔎 Ask Thinkapedia another question