Algorithm Formula
Algorithm is a step-by-step set of instructions for solving a problem or accomplishing a specific task.
The Formula
Ask yourself: Does the task need a complete list of exact steps that always ends with the right answer for any allowed input?
Quick example
What this formula means
A step-by-step set of instructions for solving a problem or accomplishing a specific task. An algorithm must be precise (every step is unambiguous), finite (it terminates after a bounded number of steps), and effective (each step can actually be carried out).
An algorithm is like a recipe written for a robot cook: every amount is measured, every step is spelled out, and the last step says stop. A person can guess what 'a pinch' means; the robot cannot, so nothing is left to guess. Unlike most recipes, a good algorithm must also work for every input it is allowed to get, not just one.
Formal view
Worked examples
Example 1
easyShow solution
Answer
First step
Full solution
- 2. Step 2: Write clear, unambiguous steps: 1. Fill kettle with water. 2. Boil the kettle. 3. Place tea bag in cup. 4. Pour boiling water into cup. 5. Wait 3 minutes. 6. Remove tea bag. 7. Add milk if desired.
- 3. Step 3: Verify the algorithm is complete (handles start to finish) and each step is precise enough for anyone to follow.
Example 2
mediumExample 3
easyCommon mistakes
- Writing steps that are ambiguous or assume human judgment the computer cannot replicate
- Forgetting to handle edge cases such as empty input or extreme values
- Creating an algorithm that works for one example but fails on other valid inputs
Common mistakes guide
If this formula keeps breaking in real problems, read the most common errors before you practice again.
Why this formula matters
Once you can write an algorithm, you can hand a job to a computer or to another person and trust the result, even for inputs you never tried yourself. Steps like 'add a little' or 'keep going until it looks right' fail, because a computer cannot guess what you meant, and steps that never end never give an answer at all.
Frequently asked questions
What is the Algorithm formula?
A step-by-step set of instructions for solving a problem or accomplishing a specific task. An algorithm must be precise (every step is unambiguous), finite (it terminates after a bounded number of steps), and effective (each step can actually be carried out).
How do you use the Algorithm formula?
Use an algorithm when a task needs a step-by-step method that works every time, for any input: sorting, searching, counting, adding big numbers, finding a route. Ask for exact steps and a clear stop. If the task is only to split a big job into smaller jobs, that is Decomposition. If it is only about doing steps in the right order, that is Sequence; if it is only about repeating a step, that is Iteration.
Why is the Algorithm formula important in CS Thinking?
Once you can write an algorithm, you can hand a job to a computer or to another person and trust the result, even for inputs you never tried yourself. Steps like 'add a little' or 'keep going until it looks right' fail, because a computer cannot guess what you meant, and steps that never end never give an answer at all.
What do students get wrong about Algorithm?
Algorithms must work for all valid inputs, not just specific examples.