What is an algorithm?
An algorithm is a precise, ordered sequence of steps that solves a problem or completes a task. In National 5 Computing Science you design algorithms before writing code, using pseudocode, a structure diagram or a flowchart. A good algorithm has a clear input, process and output, and it always finishes. Example: Find the average of three test marks: 60, 70 and 80. 1. Input mark1, mark2, mark3 2. Set total to mark1 + mark2 + mark3 (210) 3. Set average to total ÷ 3 (70) 4. Output average Answer: The algorithm outputs 70.
An algorithm is a set of clear, ordered instructions for solving a problem. It is independent of any programming language, so the same algorithm can be coded in Python or another language. In National 5 Computing Science, algorithms are usually designed in pseudocode, a structure diagram or a flowchart, and then implemented and tested. A well-designed algorithm identifies its inputs, processes and outputs, and each step is unambiguous.
Worked example
Design an algorithm to calculate the average of three test marks, then trace it with the marks 60, 70 and 80.
- Input mark1, mark2 and mark3 (60, 70, 80).
- Set total to mark1 + mark2 + mark3, so total = 210.
- Set average to total ÷ 3, so average = 70.
- Output average.
Answer: The algorithm outputs an average of 70.
Want one-to-one support?
One-to-one online tuition can help you build confidence in your subject. Find a tutor who teaches your course.
Find a TutorLearn face to face in Glasgow
Prefer in-person lessons? Visit the ExpertTutor Glasgow Southside centre.
See the centre