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....

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

Question 1 Report

The flowchart below shows an algorithm that processes an array of 5 numbers.

diagram

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]

INums[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]

Answer Details

(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]

INums[I]Nums[I] < Min?Min
Start--14
28Yes (8 < 14)8
322No (22 < 8 is false)8
43Yes (3 < 8)3
511No (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]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning