Back
⚙️Algorithms

Step-by-step problem solving

⚙️

Algorithms: Step-by-Step Problem Solving

Key Points

  • An ALGORITHM is a clear, step-by-step set of instructions that solves a problem
  • Good algorithms are: finite (they end), clear (no ambiguity), and effective (they actually work)
  • Even recipes are algorithms — they have inputs (ingredients), steps (instructions), and output (the dish)!
  • Computers run algorithms billions of times per second to do everything from searches to games

📘 Examples

Write an algorithm to find the largest number in: 5, 3, 8, 1

1. Assume first number (5) is largest. 2. Compare to next: 3 < 5, no change. 3. Compare 8 > 5 → new largest = 8. 4. Compare 1 < 8. Done! Largest = 8!

Is a recipe an algorithm? Why?

Yes! Recipes have: INPUT (ingredients), PROCESS (step-by-step instructions), and OUTPUT (the finished dish). That's an algorithm!

How would an algorithm tell if a number is even?

Step 1: Divide the number by 2. Step 2: If the remainder is 0, it's EVEN. If the remainder is 1, it's ODD. That's it — 2 steps!

🌟 Fun Fact!

The word 'algorithm' comes from the name of a 9th-century Persian mathematician: Muhammad ibn Musa al-Khwarizmi. His name was Latinized to 'Algoritmi' and eventually became 'algorithm'! 📜

An algorithm is a set of steps for solving a problem or completing a task. Recipes, directions, and long division are all algorithms, which is why the idea is more familiar than the word suggests.

What makes an algorithm interesting is that there is usually more than one for the same problem, and some are better than others. Comparing two ways of doing something is where the thinking is.

Ideas to build

  • That an algorithm must be precise and unambiguous, with no steps left to guess.
  • That the same problem can have several algorithms, and they can be compared.
  • That algorithms can be tested, and testing finds the cases you did not think about.
  • That breaking a problem down is usually the hardest and most valuable part.

Things to do at home

  • Write an algorithm for a daily task and follow it exactly, noting where it fails.
  • Compare two ways to sort a pile of cards and discuss which is quicker and why.
  • Play a guess the number game and work out the fastest strategy, which is binary search.
  • Write instructions for a simple drawing and see whether someone else can reproduce it.

Frequently asked questions

What is an algorithm in simple terms?
A set of precise steps for completing a task or solving a problem. A recipe is an algorithm, as are directions to a shop and the method for long division.
Can there be more than one algorithm for the same problem?
Yes, and comparing them is where the interesting thinking is. Some are faster, some are simpler, and working out why is a genuine computer science question.
How is an algorithm different from a sequence?
A sequence is simply steps in order. An algorithm is a complete method for solving a problem, which may include decisions and repetition as well as ordered steps.