Question 1 Report
The flowchart below shows an algorithm that processes an array of 5 numbers.
The array Nums contains: [14, 8, 22, 3, 11]
(a) State what this algorithm does. [1]
(b) Trace through the algorithm and complete the table. [4]
| I | Nums[I] | Nums[I] < Min? | Min |
|---|---|---|---|
| Start | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 |
(c) State the output of the algorithm. [1]
(d) If the algorithm needed to find the maximum instead, state one change to the flowchart. [2]
(e) State why the loop starts at I = 2 rather than I = 1. [2]
(a) The algorithm finds the minimum (smallest) value in the array. [1]
It initialises Min to the first element, then compares each subsequent element to Min, updating Min whenever a smaller value is found.
(b) Trace table for Nums = [14, 8, 22, 3, 11]: [4]
| I | Nums[I] | Nums[I] < Min? | Min |
|---|---|---|---|
| Start | - | - | 14 |
| 2 | 8 | Yes (8 < 14) | 8 |
| 3 | 22 | No (22 < 8 is false) | 8 |
| 4 | 3 | Yes (3 < 8) | 3 |
| 5 | 11 | No (11 < 3 is false) | 3 |
[1] for correct Nums values, [1] for correct Yes/No comparisons, [1] for Min changing to 8 at I=2, [1] for Min changing to 3 at I=4.
(c) The output is: 3 [1]
(d) To find the maximum instead: change the comparison from Nums[I] < Min to Nums[I] > Min. [1] You would also rename the variable Min to Max for clarity. [1] With this change, the algorithm would track the largest value seen so far and output 22.
(e) The loop starts at I = 2 because Min is already initialised to Nums[1]. [1] Comparing Nums[1] against itself at I = 1 would be redundant since the result is always false (a value is never less than itself). Starting at I = 2 avoids this unnecessary comparison while still being correct because the first element has already been accounted for in the initialisation step. [1]
Everything you need to excel in your exams