Introduction to Programming

Lesson 2 of 7

Algorithms

Master step-by-step thinking by creating and refining precise algorithms for computers to follow.

🟢 Beginner 60 XP

Learn it

An algorithm is just a fancy word for a step-by-step plan to solve a problem. Think of it like a recipe for baking a cake or instructions for building a Lego spaceship.

Every single step in an algorithm must be in the correct order and completely unambiguous. If you forget to crack the eggs before baking, your cake will be ruined!

Key terms

Algorithm
An ordered sequence of clear, unambiguous steps designed to complete a task or solve a problem.
Sequence
The exact order in which instructions are executed by a computer.
Pseudocode
A plain English outline of an algorithm that mimics code structure without strict syntax.
Efficiency
A measure of how quickly and with how little memory an algorithm accomplishes its goal.

Designing a Robust Algorithm

Follow these foundational stages when breaking down any complex computational problem.

  1. 1Define the Goal: Identify the exact input data you receive and the required output you must produce.
  2. 2Decomposition: Break down the big problem into smaller, manageable sub-tasks.
  3. 3Sequencing: Arrange the sub-tasks into a strict chronological order with clear starting and stopping points.
  4. 4Edge Case Testing: Test your steps against unusual situations, such as missing ingredients or negative numbers.

Morning Routine Algorithm in Pseudocode

textSTART
  Wake up when alarm sounds
  IF room is dark THEN
    Turn on bedroom light
  END IF
  Brush teeth for 2 minutes
  Eat healthy breakfast
  Put on school uniform
STOP

This pseudocode defines a clear, sequential path with a condition for handling a dark room before finishing the routine.

Try it

Arrange the steps of a tea-making algorithm into the correct chronological order.

  • 1Pour boiling water into the mug
  • 2Add milk and stir thoroughly
  • 3Place a teabag inside your favourite mug
  • 4Fill kettle with water and switch it on
  • 5Allow tea to brew for three minutes and remove teabag

Challenge

Write a 5-step algorithm in plain English that guides a robot from the entrance of your house to your bedroom desk.

Pick whichever way suits you — every mode earns the same bonus XP.

Write at least 40 more characters to submit.

Mark your own work

Guided walkthrough — 0/5 clues revealed

  1. Clue 1 locked — reveal it only if you get stuck.
  2. Clue 2 locked — reveal it only if you get stuck.
  3. Clue 3 locked — reveal it only if you get stuck.
  4. Clue 4 locked — reveal it only if you get stuck.
  5. Clue 5 locked — reveal it only if you get stuck.

Each clue costs 3 XP (never below 15 XP). You'd earn 30 XP right now.

Extension: Add an IF condition to your algorithm to handle a closed bedroom door.

Quiz time

Question 1 of 4Score 0

What is an algorithm?