Cambridge AS Level Computer Science 9618 · 10.2 Arrays

Q26 · 9618/23/O/N/23 Q2

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.

Q269618/23/O/N/23original Q2Structured · 9 marks
Question 2 from 9618/23/O/N/23

Worked solution

(a)

Draw the flowchart in this order, joining each box to the next with an arrow:

START → process box: Min ← Data[1] and MinIndex ← 1 [1]

→ process box: Index ← 2, then a decision diamond Is Index > 30? that starts the loop [1]

YES leads out of the loop. NO leads to a second decision diamond: Is Data[Index] < Min? [1]

YES leads to a box: Min ← Data[Index] and MinIndex ← Index. NO skips it. Both go to a box Index ← Index + 1, which loops back to the first diamond [1]

When Index > 30, go to an output box: OUTPUT MinIndex, then END [1]

Any loop that covers all 30 values is accepted, such as counting from 1 to 30.

(b)

Write both points.

An array makes the algorithm simpler to write, understand, test and debug [1]

A loop can be used to go through the values, with many values stored under one identifier [1]

(c)

DECLARE Data : ARRAY[1:120] OF REAL

Array bounds [1:120] [1]

Data type REAL for values with decimals [1]

KEY IDEATo find a smallest value, start with the first element, compare the rest in a loop and keep its index.
TOTAL 9 marks

Official mark scheme

Mark scheme for 9618/23/O/N/23 question 2
VIDEO
▶ Starts at Q2 (27:32)

Starts at Q2 (27:32) · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.