What is an Algorithm for Kids? An Introduction to Algorithms for Kids

What is an algorithm for kids?

Algorithm is a pretty big word.

Even if you aren’t quite sure what algorithm means, there is a chance you have heard people talk about computer algorithms.

But what exactly is an algorithm?

An algorithm is a set of step-by-step instructions that describe how to perform a task.

These steps are used to solve a problem or reach a result.

Algorithms are like recipes

At Inspirit AI, we like to compare algorithms to making a recipe.

Algorithms are used in computer science and programming – not cooking – but algorithms work similar to recipes!

To make a peanut butter and jelly sandwich, you follow a specific process and set of steps:

  1. Put two pieces of bread on a plate.
  2. Use a knife to spread peanut butter onto one piece of bread.
  3. Use a knife to spread jelly onto the other piece of bread.
  4. Put the pieces of bread together to make a sandwich.
  5. Take a bite!

Once you have created your PB&J, you can share your recipe with friends who now know how to recreate the process.

If you give your friend specific and clear directions, they can create a PB&J, just like yours!

Algorithms are specific and clear

If your directions aren’t very easy to follow, your friend might end up reaching a different result.

For example, let’s take a look at the following directions:

  1. Put the bread on a plate.
  2. Spread peanut butter onto the bread.
  3. Spread jelly onto the bread.
  4. Make a sandwich.
  5. Take a bite!

To a human who has made a PB&J before, these directions might make sense! But they aren’t nearly specific enough for a computer!

A computer might wonder:

  • How much bread? How much peanut butter? How much jelly?
  • What should I use to spread the peanut butter and jelly with?
  • How do I make a sandwich?
  • What should I take a bite of?

An unclear, unspecific algorithm may put you in a sticky situation!

Algorithms are lines of code

Even though the PB&J example is fun and easy to digest, algorithms are used in computer science – not cooking.

In computer science and programming, algorithms consist of lines of code that can solve problems (like math problems).

Computer algorithms have three main goals:

  • To accomplish a task
  • To analyze the information
  • To share results with humans!

In our unplugged example of making a PB&J, our algorithm had the following goals:

  • To accomplish a task: Make a PB&J sandwich
  • To analyze the information: Use the ingredients and materials to accomplish our task
  • To share results with humans: Take a bite and share with friends!

In computer science, we use algorithms in several different ways:

  • We already shared that algorithms can be used to solve problems.
  • Algorithms can also sort and search through lists and information.
  • And we even use algorithms for artificial intelligence!

Algorithms are everywhere

Algorithms are all around us!

Google uses algorithms to rank search results, or decide the order websites appear when you search.

YouTube is another popular algorithm! You can search for videos (just like how you search on Google). Once you finish watching one video, YouTube will recommend other videos for you to watch.

Social media uses algorithms to recommend posts to users, based on their history.

What other examples of algorithms have you seen online? In our recent blog post all about artificial intelligence for kids, we share even more examples of algorithms in the world around us!

How do you write an algorithm?

Algorithms are a set of step-by-step directions – and we can write them using code!

We can even use an algorithm to write… an algorithm!

  • Step #1: Think about what you want your algorithm to do
  • Step #2: Write out each step (in code!)
  • Step #3: Test your code
  • Repeat any necessary steps until your code is complete!

Let’s take a deeper look at each of these steps to writing an algorithm.

1. Think about what you want your algorithm to do

Algorithms accomplish a task. That means they have an objective or a goal.

What do you want your algorithm to do?

Spend some time thinking and brainstorming before you start coding. This will help make the process easier!

 

2. Write out each step (in code!)

Once you have decided on an objective, you can start coding!

As you begin to write your code, make sure you write out each step. Be clear and specific with your code.

This step is important to make sure your algorithm actually works.

 

3. Test your code

Test out your code! Does your algorithm work?

You might notice that your code does not run correctly on the first try, and that’s okay.

In fact, that’s great!

Coding is all about solving problems and learning from your mistakes.

(In computer science, we call the mistakes in our code “bugs.”)

 

How can you get more practice writing algorithms?

At Inspirit AI, we introduce elementary and early middle school students to computer science using Scratch, a block-based programming tool.

One way to practice writing algorithms is to code your own game in Scratch. We have even put together 5 Scratch project ideas for kids.

The best way to get more practice writing algorithms is to take a class!

Inspirit AI offers online coding classes for students of all ages, developed by Stanford and MIT graduates. Apply to our programs to learn more about algorithms for kids!

Learn more about our elementary school offerings here.

Learn more about our middle school offerings here.

Meet our team here.