Find a course

Module 1: Thinking Like a CoderLesson 2 of 79 min

Algorithms and Sequences

An algorithm is a step-by-step plan. Learn why order matters, guide a robot across a grid, and spot steps that are in the wrong place.

Step 1 of 12Learn

Plans with steps

Before coders write code, they make a plan. A step-by-step plan for doing a task is called an algorithm.

You use algorithms every day. Brushing your teeth is one: get the toothbrush, put on toothpaste, brush, rinse. A recipe is an algorithm. So are the directions to your friend's house.

A good algorithm has steps that are clear, in the right order, and has a clear end.

Step 2 of 12Practice · Diagram

An algorithm for brushing teeth

Which step comes right after adding toothpaste?

Tap the shape that answers the question, then press Check.

An algorithm for brushing teethProcess diagram: Get brush → Add toothpaste → Brush → Rinse → Done!.Get brushAdd toothpasteBrushRinseDone!
Get brush
Add toothpaste
Brush
Rinse
Done!

Step 3 of 12Practice · Put in order

Put this algorithm for planting a seed in order.

Drag the items, or use the arrow buttons, to put them in order.

  1. Drop in the seed
  2. Water it
  3. Poke a small hole
  4. Cover it with soil
  5. Fill a pot with soil

Step 4 of 12Learn

Order matters

Steps that run one after another are called a sequence. Computers always run code from top to bottom, one line at a time.

If the order is wrong, the result is wrong. Try putting on your shoes and then your socks. Silly!

Coders often test an algorithm by acting it out or tracing it with a finger, step by step, before they type any code.

Step 5 of 12Compare

Order matters!

AspectRight orderWrong order
Step 1Put on socksPut on shoes
Step 2Put on shoesPut on socks
ResultReady to go!Socks on top of shoes. Silly!

Step 6 of 12Practice · Spot the mistake

One step of this algorithm for making toast is in the wrong place. Tap it.

Step 7 of 12Tap to reveal

Guiding a robot on a grid

  1. The commands

    Our robot knows three commands: forward (move one square), turn left and turn right (spin on the spot without moving).

  2. The goal

    The robot starts facing right. A star is 2 squares to the right and then 1 square up.

  3. The algorithm

    forward, forward, turn left, forward. Two moves right, a quarter turn to face up, then one move up.

Step 8 of 12Practice · Put in order

The robot starts facing right. Put the commands in order so it goes 1 square right, then 2 squares up.

Drag the items, or use the arrow buttons, to put them in order.

  1. turn left
  2. move forward 2 squares
  3. move forward 1 square

Step 9 of 12Note

Step 10 of 12Practice · Choose one

Which is the best algorithm step for a robot?

Step 11 of 12Practice · What would you do?

What would you do?

You wrote directions for a classmate to draw a house: "Draw a roof. Draw a square under it." They drew a tiny roof in one corner and a huge square across the page. What is the best fix?

Step 12 of 12Practice · Fill in the blanks

Fill in the blanks

A step-by-step plan for solving a problem is called an .

Word bank