9618/23/O/N/23 question 5: worked solution (October/November 2023, paper 23)

Show as plain text

Cambridge AS Level Computer Science 9618 · 9.2 Algorithms Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2. Q34 9618/23/O/N/23 original Q5 Structured · 6 marks Worked solution Dry run Process(2). Mix starts as 4, 2, 3, 5. The loop runs while Total < 20. Index Value Total Mix [1] Mix [2] Mix [3] Mix [4] 2 0 4 2 3 5 3 2 2 4 5 3 5 4 3 5 4 5 8 5 2 5 10 4 5 8 9 2 5 15 4 13 8 9 2 13 28 4 21 8 9 2 13 28 56 21 8 9 Initialisation row [1] Loop 1 correct (Total 2) [1] Loop 2 correct (Total 5) [1] Loop 3 correct (Total 10) [1] Loop 4 correct (Total 15) [1] Loop 5 correct (Total 28), then the final line Mix [1] ← 28 * 2 = 56 [1] Notes: when Index is 4 the ELSE branch adds Mix [1] to Mix [4] . The new Index is (Value MOD 4) + 1, for example (13 MOD 4) + 1 = 2. KEY IDEA In a trace, apply MOD and the IF branch carefully each time and update only what each line changes. TOTAL 6 marks Official mark scheme VIDEO ▶ Starts at Q5 (1:13:13) Starts at Q5 (1:13:13) · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.