9618/22/O/N/23 question 5: worked solution (October/November 2023, paper 22)
Show as plain textHide 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. Q32 9618/22/O/N/23 original Q5 Structured · 6 marks Worked solution Dry run Process(3) one line at a time. Mix starts as 1, 3, 4, 2. Each row below shows the values after one pass of the loop. Index Value Count Mix [1] Mix [2] Mix [3] Mix [4] 3 0 1 3 4 2 4 4 1 1 3 3 2 2 2 2 1 3 3 1 3 3 3 1 2 3 1 3 3 4 1 2 2 1 2 2 5 1 2 1 1 2 2 5 1 2 1 10 Initialisation row (Index 3, Count 0, Mix 1, 3, 4, 2) [1] Loop 1 and loop 2 rows correct [2] Loop 3 and loop 4 rows correct [2] Loop 5 row correct, then the last row where Mix [4] ← 5 * 2 = 10 [1] Marks are earned for each correct row, so check each Mix change: loop 1 changes Mix [3] to 3, loop 2 changes Mix [4] to 1, loop 3 changes Mix [2] to 2, loop 4 changes Mix [3] to 2, loop 5 changes Mix [3] to 1. KEY IDEA Work through a trace table line by line and update only the variable that each line changes. TOTAL 6 marks Official mark scheme VIDEO ▶ Starts at Q5 (26:45) Starts at Q5 (26:45) · by Pseudocode Pro. Tap the picture to open it on YouTube.