📋
AI🚀 Ages 7-10Beginner 6 min read

Algorithms in AI

A friendly primary lesson on algorithms in AI: what a step-by-step recipe is, how computers follow rules, and how AI learns its own steps from examples.

Key takeaways

  • An algorithm is a list of steps that solves a problem, like a recipe
  • Computers are very good at following steps quickly and exactly
  • Some AI algorithms are written by people, step by step
  • Other AI algorithms learn their own steps by looking at lots of examples
  • A computer only does what its steps tell it to do, so the steps must be clear

A recipe is a kind of algorithm

Have you ever made pancakes? You follow steps. First you mix flour, milk and egg. Then you heat the pan. Then you pour in the batter. Then you flip the pancake. If you follow the steps in the right order, you get a yummy pancake every time.

That list of steps has a special name. It is called an algorithm. An algorithm is just a clear list of steps that solves a problem. A recipe solves the problem "How do I make pancakes?" The steps to brush your teeth are an algorithm too. So are the steps to tie your shoes.

Computers love algorithms. In fact, a computer cannot do anything without an algorithm. A computer needs someone to give it clear steps to follow. Then it follows those steps very, very fast.

Computers follow steps exactly

Here is something important about computers. A computer does exactly what the steps tell it to do. It does not guess. It does not fill in missing bits. It does not say "I think you meant this."

Imagine you give a robot these steps to make a jam sandwich:

  1. Pick up the bread.
  2. Put jam on it.
  3. Done.

A person knows what you mean. But a computer might put jam on the outside of the bread, because you never said which side! That sounds silly, but it shows the big idea: the steps have to be clear and complete. If a step is missing or fuzzy, the computer gets stuck or does the wrong thing.

This is why people who write algorithms think very carefully. They break a job into tiny, clear steps and put them in the right order. Getting the order right matters a lot. You cannot flip a pancake before you pour the batter!

Where do AI algorithms come from?

So far, all our algorithms were written by people. A person thinks of the steps and writes them down. Lots of computer programs work this way, and they are very useful.

But AI can do something extra. AI stands for artificial intelligence. With AI, the computer can learn some of its own steps by looking at many examples. If you want to know more about how that works, you can read How Does AI Learn?.

Let me show you the difference with a real example: telling cats from dogs in photos.

The written-by-people way. A person tries to write the steps: "If it has pointy ears AND whiskers AND a small nose, say cat." But this is really hard! Some dogs have pointy ears too. Some cats look unusual. There are too many exceptions to write down. The steps get longer and longer and still make mistakes.

The learning way. Instead, you show the AI thousands of cat photos labelled "cat" and thousands of dog photos labelled "dog". The AI looks for patterns all by itself. It slowly works out its own steps for telling them apart. Nobody had to write "look for pointy ears." The computer found the useful clues on its own. This is called machine learning, and you can explore it in What Is Machine Learning?.

Two kinds of algorithms, side by side

Written by peopleLearned by AI
Who makes the steps?A person writes each stepThe computer finds them from examples
Good forClear tasks with simple rulesMessy tasks like spotting cats in photos
ExampleSteps to add two numbersTelling cats from dogs

Both kinds are real algorithms. Both are just steps a computer follows. The big difference is who came up with the steps.

What an algorithm cannot do

It is easy to think a computer is clever, but really it is just following steps very fast. An algorithm has no feelings and no common sense. It does not understand the world like you do.

If the steps are wrong, the answer will be wrong, even if the computer runs them perfectly. People say "garbage in, garbage out." That means bad steps or bad examples give bad results. A learning AI can also be fooled if it only saw examples of one kind. If it only ever saw small dogs, it might be confused by a giant dog.

So the next time your tablet sorts your photos or a game character chases you, remember: behind it all is an algorithm. It is a list of clear steps, written by a person or learned from examples, that a computer follows step by step by step.

A quick challenge

Try this at home. Write an algorithm for making a bowl of cereal. Write every single step, even the tiny ones. Then ask a grown-up to follow your steps exactly, doing nothing you did not write. Did they get cereal? Or did they get stuck because a step was missing? That is exactly the puzzle that AI engineers solve every day.

Quick quiz

Test yourself and earn XP

What is an algorithm?

Why must the steps in an algorithm be very clear?

How does a learning AI get its steps?

Which everyday thing works like an algorithm?

FAQ

No. Most algorithms are simple step-by-step rules, like the steps a calculator uses to add numbers. AI uses special algorithms that can learn from examples, but plenty of useful algorithms never learn anything; they just follow fixed steps.

Yes! Every time you write clear steps for a task, like how to brush your teeth or tie your shoes, you are writing an algorithm. Putting the steps in the right order is the most important part.