Higher Computing Science
Standard algorithms with arrays of records
Higher Computing Science: Software design and development
The biggest marks in Section 1, often 4 to 6 at a time, are for writing a standard algorithm, usually on an array of records. The papers never name the algorithm: they describe a task. The examiners' reports for 2023 and 2024 add one firm rule: write it yourself.
The data
A pony-trekking centre stores its treks as an array of records:
RECORD Trek IS {STRING name, REAL hours, REAL price}
DECLARE treks AS ARRAY OF Trek INITIALLY [] * 30
Find minimum: the cheapest trek
SET minPos TO 0
FOR index FROM 1 TO 29 DO
IF treks[index].price < treks[minPos].price THEN
SET minPos TO index
END IF
END FOR
SEND treks[minPos].name TO DISPLAY
Start with the first element. A starting value of 0 would never be beaten by a price, so the "cheapest" would always be wrong. Keeping the position lets you display any field of the winning record.
Count occurrences: short, cheap treks
SET count TO 0
FOR index FROM 0 TO 29 DO
IF treks[index].hours < 2 AND treks[index].price <= 40 THEN
SET count TO count + 1
END IF
END FOR
Linear search: is a trek on offer?
SET found TO FALSE
SET index TO 0
WHILE found = FALSE AND index < 30 DO
IF treks[index].name = target THEN
SET found TO TRUE
ELSE
SET index TO index + 1
END IF
END WHILE
IF found = FALSE THEN
SEND "Not on offer" TO DISPLAY
END IF
- Your own loop and IF. A built-in such as
min(),max()or a sort does not show the algorithm, so it cannot gain the marks. - Minimum or maximum: a suitable starting value (the first element), and updating the position when a better one is found.
- Count: set the counter to 0 before the loop and add 1 inside it, under the right condition.
- Search: found starts FALSE and becomes TRUE on a match; the "not found" message comes after the loop, so it appears once.
- Record and field:
treks[index].price, nottreks.price[index].
Parallel arrays instead?
If the question asks for an array of records and you write the algorithm with parallel arrays, the marks for the names are lost but the algorithm marks are kept. Better to use what the question gives you.
Try two exam-style questions
Choose an answer, say how sure you are, then press Check. Every wrong answer tells you why it is wrong.
The full course covers every topic like this. Every topic in Higher Computing Science has a short note, and a practice quiz with feedback on every answer, plus coding lessons in Python, SQL and HTML, a full mock exam and a progress report for parents.
More guides
This site is independent: it is not connected to the SQA or Qualifications Scotland. Points from the examiners' course reports are given in our own words.