What standard algorithms must a National 5 programmer know how to design and code?
Standard algorithms: input validation, running total within a loop, and traversing a 1-D array, each as a reusable pattern built from selection and iteration.
An SQA National 5 Computing Science answer on the three standard algorithms, covering input validation with a conditional loop, keeping a running total inside a loop, and traversing a one-dimensional array with a fixed loop, with worked code-style examples of each reusable pattern.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this key area is asking
The SQA wants you to design and write the three standard algorithms every National 5 programmer must know: input validation, keeping a running total within a loop, and traversing a one-dimensional array.
What "standard algorithm" means
The three required at National 5 are all built from the constructs of selection and iteration: input validation and running total use loops, and traversing an array is itself a loop over indexes.
Input validation
Validation protects a program from bad data: an age of -5, a percentage of 200, or a menu choice that is not on the menu. The condition in the loop describes what is wrong, so the loop runs while the input is invalid and stops as soon as it is valid.
Running total within a loop
The single most important step is initialising the total to zero before the loop starts. If you forget, the total starts with whatever was previously in memory; if you set it to the first value instead, you may count that value twice or miss it.
Traversing a 1-D array
Because an array has a known number of elements, a fixed (count-controlled) loop is the natural choice: the loop variable steps through the indexes and the body does something with each element.
Why these three
These patterns appear constantly: almost any program that reads user input needs validation, almost any program that handles a list needs traversal, and almost any program that sums or averages needs a running total. Knowing them as ready-made patterns means you spend exam time fitting the pattern to the problem, not reinventing it under pressure.
How this key area is examined
Questions name the algorithm and ask you to write it in a high-level language, or give code and ask you to identify which standard algorithm it is. For input validation, show the first input, a conditional loop with an "invalid" condition, and a re-read inside. For a running total, zero the total first and add inside the loop. For traversal, use a fixed loop over the indexes. These are patterns, so practise them until you can write each from memory.
For the official course specification
The SQA publishes the full National 5 Computing Science course specification, specimen question papers and coursework tasks at sqa.org.uk. Always revise from the current specification and SQA past papers, because question style and terminology are board-specific.
Exam-style practice questions
Practice questions written in the style of SQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
SQA N5 style4 marksWrite code using the input validation standard algorithm to make sure a percentage entered is between 0 and 100 inclusive.Show worked answer →
Four marks for a correct validation loop that rejects out-of-range values and keeps asking.
Example (Python):
mark = int(input("Enter percentage: "))
while mark < 0 or mark > 100:
print("Invalid - must be 0 to 100.")
mark = int(input("Enter percentage: "))
Markers reward the first input before the loop, a conditional loop with the correct condition (mark < 0 or mark > 100), re-reading the value inside the loop, and the loop ending only when a valid value is entered. This is the input validation standard algorithm.
SQA N5 style3 marksAn array temps holds 7 daily temperatures. Write code using the running total standard algorithm to calculate their total.Show worked answer →
Three marks for setting the total to zero, traversing the array, and adding each element.
Example (Python):
total = 0
for index in range(0, 7):
total = total + temps[index]
Markers reward initialising total to 0 before the loop (a common point to miss), a loop that visits every element, and adding the current element to the running total each pass. Forgetting to set total to 0 first, or starting it at the first element, is the usual error.
Related dot points
- Computational constructs: assignment, arithmetic, comparison and logical operators, concatenation, predefined functions, and the control structures of selection and iteration (fixed and conditional).
An SQA National 5 Computing Science answer on computational constructs, covering assignment, arithmetic, comparison and logical operators, string concatenation, predefined functions, and the control structures of selection (IF) and iteration (fixed and conditional loops) used to build programs in a high-level language.
- Data types and structures: variables holding character, string, numeric (integer and real) and Boolean values, and the 1-D array as a structure for holding many values of the same type under one name.
An SQA National 5 Computing Science answer on data types and structures, covering the variable types of character, string, integer, real and Boolean, when each is chosen, and how a one-dimensional array stores many values of the same type under a single name accessed by an index.
- Design techniques: representing a program design with structure diagrams, flowcharts and pseudocode, and designing the user interface with a wireframe.
An SQA National 5 Computing Science answer on design techniques, covering how developers plan a program using structure diagrams, flowcharts and pseudocode, how to read and write each notation, and how a wireframe is used to design the layout of a user interface before coding begins.
- Testing with normal, extreme and exceptional test data; the three kinds of error (syntax, execution and logic); and evaluating software for fitness for purpose, efficiency, robustness and readability.
An SQA National 5 Computing Science answer on testing and evaluation, covering the three categories of test data (normal, extreme and exceptional), the three kinds of error (syntax, execution and logic), and the four criteria for evaluating software: fitness for purpose, efficiency, robustness and readability.
- The iterative software development process: analysis, design, implementation, testing, documentation and evaluation, and why the process is iterative rather than strictly linear.
An SQA National 5 Computing Science answer on the software development process, covering the six stages of analysis, design, implementation, testing, documentation and evaluation, what is produced at each stage, and why the process is iterative so that developers loop back to earlier stages when problems are found.