Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q36 · 9618/22/M/J/24 Q2

Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.

Q369618/22/M/J/24original Q2Structured · 10 marks
Question 2 from 9618/22/M/J/24

Worked solution

(a)

Fill the shapes like this:

First decision: is Num1 > Num2 AND Num1 > Num3? [1]

Yes: set Ans to Num1 [1]

No leads to a second decision: is Num2 > Num3? Yes: set Ans to Num2; No: set Ans to Num3 [1]

Process box after the three branches join: set Average to (Num1 + Num2 + Num3) / 3 (do not use DIV) [1]

Output parallelogram: OUTPUT a message with Ans and Average [1]

(b)

The outer loop repeats until Flag is TRUE. Inside it, Port goes 1 to 3 (the flowchart stops when Port = 4).

Flag ← GetStat()
WHILE Flag <> TRUE
    FOR Port ← 1 TO 3
        CALL Reset(Port)
    NEXT Port
    Flag ← GetStat()
ENDWHILE

Outer conditional loop that tests Flag [1]

Flag assigned from GetStat() inside the loop (and before it) [1]

Inner loop that counts Port [1]

Inner loop runs for 3 iterations (Port 1, 2, 3) [1]

CALL Reset(Port) inside the loop [1]

A REPEAT ... UNTIL Flag = TRUE with an IF around the FOR loop also scores.

KEY IDEARead a flowchart's decisions and loops carefully, then match them to WHILE or FOR loops.
TOTAL 10 marks

Official mark scheme

Mark scheme for 9618/22/M/J/24 question 2
VIDEO
▶ Starts at Q2 (13:11)

Starts at Q2 (13:11) · by Pseudocode Pro. 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.