SDD  ·  Revision  ·  Section D

Which Standard Algorithm?
Search, Extremes, Counting or Totals

Software Design & Development revision Approx 30–40 min 8 scenarios  ·  justification practice
Recap: The SQA N5 specification names three standard algorithms: input validation (a WHILE loop that keeps re-asking until a value is within an acceptable range), a running total (an accumulator, initialised to 0 before the loop, that has a value added to it each iteration), and traversing a one-dimensional array — visiting every element with a FOR loop to run a linear search for a target (using a found flag and position), find a minimum/maximum (initialised to the first element, compared with < or >), or count matches (initialised to 0, incremented when a condition is true).  → SDD11  ·  SDD12  ·  SDD13  ·  SDD14  ·  SDD15
How to use this drill: Each scenario names a specific situation and offers two of the five standard-algorithm patterns to choose between — read carefully, because the two options change from scenario to scenario. Select the algorithm that fits, then write a justification naming the pattern (e.g. initialisation value, comparison operator, what the accumulator or flag is doing) and the exact detail in the scenario that rules out the other option. Reveal the model answer to check your reasoning.
Your choices and justifications are saved automatically.
Section D — Which Standard Algorithm?

Eight scenarios, each offering a different pair of standard algorithms. Select the algorithm that best fits, justify your choice using the scenario, then check the model answer. Scenarios 5 and 8 are marked DISCUSS — either answer can be correct if well-justified.

Scenario 1 of 8 Coldest day at the weather station

The school's weather-station club, run by Mr Reid, logs six hourly temperature readings (°C) each school day into an array. He wants a program that identifies the single lowest reading of the day — not how many readings fell below a given threshold, which is a separate question he isn't asking here.

Expected: Minimum Initialise minimum = readings[0], then loop from index 1 comparing each remaining element with <, updating minimum whenever a smaller value is found. This is not Count: a counter starts at 0 and only tracks how many times a condition is true, but Mr Reid wants the actual lowest value itself, not a tally of readings meeting some condition.
Scenario 2 of 8 Full-marks tally in a spelling test

Mrs Adams stores 30 pupils' spelling test scores (out of 10) in an array. She wants to know how many pupils scored a perfect 10 — not what the highest score in the class was, since she already knows the maximum possible score on this test is 10 and that isn't what she's asking for.

Expected: Count Initialise count = 0, then loop through every index and increment count whenever scores[index] == 10. This is not Maximum: Mrs Adams already knows the largest possible score is 10, so finding the extreme value would tell her nothing new — what she needs is a tally of how many pupils actually reached it.
Scenario 3 of 8 Locating a runner's finish position

Mr Boyle stores the race numbers of every finisher of the school cross country in an array, in the order they crossed the line. A pupil types their own race number, and he wants the program to report which position in the array it was stored at — or state that it wasn't found. He does not need to know which finish time was fastest.

Expected: Linear search Set found = False and position = -1, then loop through the array with FOR index: if array[index] == target, set found = True and position = index. This is not Minimum: the pupil's race number is a target being matched for equality, not an extreme value being tracked with < or > — and Mr Boyle explicitly needs the array position, which only search reports.
Scenario 4 of 8 Total takings from the tuck shop

The tuck shop's volunteer rota records every individual sale amount (in pounds) from the day into an array as the till is cashed up. The treasurer wants the program to add up every sale to get the day's total takings — not how many sales were made, which she can already see from how many rows are in the till roll.

Expected: Running total Initialise total = 0 before the loop, then on every iteration add the actual sale amount: total = total + sales[index]. This is not Count: a counter would only add 1 per sale regardless of its value, but the treasurer needs the sum of the real amounts, in pounds, not a tally of how many sales occurred.
Scenario 5 of 8 Totalling five sponsorship donations Discuss

A charity event program asks a volunteer to enter 5 sponsorship donation amounts, one after another. Each amount must be greater than £0 before it is accepted — the program keeps re-asking for that donation until a valid amount is entered. Once a valid donation has been entered, it is added to a running total, which is displayed after all 5 donations have been collected.

Expected: Either — if justified using the scenario If choosing Input validation: The scenario's defining behaviour is the WHILE donation <= 0 loop that rejects and re-asks — without it, an invalid amount could corrupt the total, so this is the pattern doing the protective work.

If choosing Running total: The overall purpose of the program, and the value actually displayed at the end, is the accumulated sum: total = 0 before the fixed loop, total = total + donation once each donation is valid. Validation is a supporting step inside it, not the end goal.

Exam note: This nests one standard algorithm inside another — input validation runs inside each iteration of the fixed loop that builds the running total, exactly as in SDD15's combined example. A weak answer names only one pattern and ignores the other. A strong answer names both and explains how they combine: validation guarantees every value the accumulator sees is valid before it is added.
Scenario 6 of 8 Checking a locker code is on the approved list

Mr Sinclair keeps an array of the PE department's approved 4-digit locker codes. When a pupil reports a code, the program checks whether that exact code appears anywhere in the array and, if so, states its position in the list. Codes are unique, so he does not need to know how many times the code matches — only where it is.

Expected: Linear search Set found = False and position = -1, then compare each element to the reported code, updating both when a match is found. This is not Count: since codes are unique a count would only ever return 0 or 1, telling Mr Sinclair nothing useful — he specifically needs the array position, which only search's position variable provides.
Scenario 7 of 8 Personal best in the long jump

Miss Okafor records a pupil's six long jump attempts (in metres) during a PE lesson into an array. She wants the program to report the pupil's single best jump of the six attempts — not the combined distance jumped across all six attempts added together, which would not tell her anything about the pupil's personal best.

Expected: Maximum Initialise maximum = jumps[0], then loop from index 1 comparing each remaining element with >, updating maximum whenever a larger jump is found. This is not Running total: summing the six jumps would give a combined distance that has no meaning as a "personal best" — Miss Okafor needs the single largest value, not an accumulated sum.
Scenario 8 of 8 Validating a canteen order against today's menu Discuss

A canteen ordering kiosk stores today's three available meal options in an array: "Pasta", "Curry", "Salad". When a pupil types their choice, the program must keep re-asking until the pupil enters text that exactly matches one of the three options stored in the array.

Expected: Either — if justified using the scenario If choosing Input validation: "Keep re-asking until the pupil enters a valid value" is exactly SDD15's re-prompt pattern — a WHILE loop wrapped around the input, matching the structure of while age < 13 or age > 120 even though the condition here is about text matching rather than a numeric boundary.

If choosing Linear search: To actually test "matches one of the three options stored in the array", the condition inside the WHILE cannot be a single simple comparison — it must traverse the array comparing the pupil's text to each stored option in turn, which is exactly SDD13's element-by-element comparison against a target.

Exam note: This is the sharpest DISCUSS case — SDD15's input validation examples always test a value against a numeric range (a boundary), not membership in a list of stored options, so checking "matches one of the array's options" genuinely needs some form of traversal-and-compare hidden inside the re-prompt loop. A strong answer notices this and names both patterns rather than forcing the scenario into whichever label it picked first.
Marker's eye view — why candidates lose marks

The most common generic error is describing the loop without naming which standard algorithm it is or giving the exact initialisation value and comparison operator. "Loop through the array and check each one" is not evidence on its own — "initialise minimum to the first element, then compare each remaining element with <" is. Always state the starting value of the key variable (0 for a counter or total, the first array element for minimum/maximum, False/-1 for a search's found flag and position) and the comparison that drives the loop.

The second common confusion is between Count and Running total: both use an accumulator that starts at 0 and updates inside the loop, but Count adds 1 each time a condition is true while Running total adds the actual value from the array — mixing these up is the single most frequent slip in this topic. A closely related mix-up is between Linear search and Minimum/Maximum: both traverse the array comparing elements, but search tests for equality against a fixed target (==), while minimum/maximum tracks an extreme value seen so far using < or > — always ask whether the program is looking for one specific known value, or working out the biggest/smallest value from values it doesn't know in advance.

For the two Discuss scenarios: state clearly which algorithm the scenario's exact wording most directly names, but where the wording nests one algorithm inside another — validation guarding a total, or a search-style comparison hidden inside a "keep asking until it matches" phrase — name both and explain how they combine, rather than forcing a single clean answer.