Skip to main content
ScotlandComputer ScienceSyllabus dot point

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.

Generated by Claude Opus 4.810 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this key area is asking
  2. What "standard algorithm" means
  3. Input validation
  4. Running total within a loop
  5. Traversing a 1-D array
  6. Why these three
  7. How this key area is examined
  8. For the official course specification

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

Sources & how we know this