Three worked examples
These examples are calculated by the same engine as the tool. Expand a solution to follow every step.
Start with 12. Multiply by 5, then add 1.
- Input 12.
- Multiply: state becomes 60.
- Add 1: output 61.
Answer: 61
Start with 9. Multiply by 2, then add 9.
- Input 9.
- Multiply: state becomes 18.
- Add 9: output 27.
Answer: 27
Start with 6. Multiply by 3, then add 8.
- Input 6.
- Multiply: state becomes 18.
- Add 8: output 26.
Answer: 26
A historical name, a wider mathematical idea
The word algorithm is connected to Latin forms of al-Khwarizmi’s name. The Library of Congress documents that link alongside his ninth-century work. [1] The name’s history does not mean that every step-by-step method began with one person. Doubling, numeral conversion and other procedures in this collection provide further ways to recognise algorithmic thinking.
For the modern concept, NIST’s Dictionary of Algorithms and Data Structures describes an algorithm as a computable set of steps directed towards a desired result. [2] The important feature in this activity is precision: another learner should be able to follow the same instructions on the same input and reach the same output. An unexplained correct number does not show whether the procedure itself was understood.
Identify input, state and output
The input is the starting number a. The current state is the value reached so far. The output is the state after all instructions have been completed. In our two-operation machine, the first state change multiplies a by b. The second adds c to that product. Written as one expression, the output is ab + c.
These labels prevent a subtle error: applying every instruction to the original input. After multiplying, the current value has changed. Adding c must act on that new value. A state log can use three short lines labelled start, after multiplication, and after addition. You do not need a computer to trace an algorithm; careful paper records perform the same bookkeeping.
Run one instruction at a time
Read the whole sequence before calculating so that you know its order and stopping point. Copy the supplied input accurately. Complete the multiplication and record that product in the first requested answer field. Then use that recorded product as the starting point for the addition. Enter the final sum in the output field.
If you make an error, find the earliest state that differs from the intended procedure. Correct that state and recompute every later state that depends on it. Editing only the final answer can hide the cause. The generated examples use different inputs, factors and additions while retaining the same structure, making them useful for practising a dependable tracing routine.
Why order changes the rule
Multiplying by b and then adding c produces ab + c. Adding c first and then multiplying produces b(a + c), which expands to ab + bc. The two rules differ because the second multiplies the added quantity as well. They agree in some special cases, but that does not make the instruction sequences interchangeable.
Written precedence and spoken procedure should also agree. The expression ab + c performs multiplication before addition. If the intended operation were addition followed by multiplication, brackets would make that grouping explicit. When an instruction list and an expression seem inconsistent, trace the states to locate the difference. This connects algorithms with the order-of-operations skill without reducing algorithmic reasoning to memorising a precedence acronym.
Explain correctness and stopping
This machine has exactly two arithmetic instructions after receiving its input, so it reaches its output after a known number of steps. Correctness has two parts: following the specified rule and calculating each operation accurately. You can perform correct arithmetic on the wrong state and still obtain the wrong output for the algorithm.
A useful check reverses the operations in reverse order. Subtract c from the proposed output, then divide by the nonzero factor b. If the result returns to the original input, your answer is consistent with the machine. This reverse trace explains why the order of inverse operations matters. It also leads naturally to solving a two-step linear equation for a hidden input.
Compare algorithms without confusing speed with correctness
A multiplication may be calculated mentally, by a written method or through doubling rows. Each can supply the multiplication stage of this machine. A faster calculation is useful only if it implements the intended operation correctly. Keep the overall algorithm separate from the chosen arithmetic technique: the sequence specifies what to do, and a multiplication method specifies how to carry out one stage.
Different algorithms can also produce the same mathematical result. The Egyptian doubling lesson and long multiplication offer an accessible comparison. Explain what data each method keeps, what changes at each step, and how it knows it has finished. This is a practical way to evaluate a procedure before discussing advanced questions about efficiency, code or the kinds of problems that computers can solve.
Common mistakes
- Adding to the original input. The addition uses the state after multiplication. Carry the latest state forward through the sequence.
- Reversing the operation order. Follow multiply, then add. Performing add, then multiply implements a different rule unless the supplied data happen to make the results coincide.
- Reporting only the final output. Record the intermediate product as requested. It shows where an error occurred and demonstrates that the intended sequence was followed.
Questions learners ask
Does an algorithm have to be computer code?
No. A precisely specified procedure can be followed on paper or mentally. Code is one way to express a procedure for a computer.
Is every recipe a useful algorithm?
A recipe can illustrate ordered instructions, but vague directions need clarification before different people can follow exactly the same procedure. This number machine makes every operation explicit.
Can two algorithms give the same answer?
Yes. Different multiplication procedures can calculate the same product. Compare their steps and reasoning as well as their final values.
Why do I reverse the inverse operations?
The last forward change is the first change you must undo. Remove the added amount before undoing the earlier multiplication.
Keep learning
Connect this method to the main Math learning path:
Sources and historical scope
The term’s historical connection to al-Khwarizmi is distinguished from the much broader history of mathematical procedures.
- Library of Congress — Al-Khwarizmi and the word algorithm ↗
- NIST Dictionary of Algorithms and Data Structures — algorithm ↗
The diagrams, examples and printable questions on this page are newly created teaching material. Historical context comes from the sources above.