9618/21/O/N/22 question 6: worked solution (October/November 2022, paper 21)

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. Q23 9618/21/O/N/22 original Q6 Structured · 7 marks Worked solution (a) NOT makes the condition TRUE when the bracket is FALSE. The bracket is FALSE if any one part fails. Write any one of these: Dots is zero (less than 1), or Ats is not equal to 1, or Others is less than 9 (not more than 8). [1] (b)(i) Run the loop one character at a time. Only the changed value is written on each row. The loop stops after the row for Index 12 because Ats becomes 2, so Valid becomes FALSE and the UNTIL condition is true. (Index then goes up to 13, but no row is needed for that.) Index NextChar Dots Ats Others Valid 0 0 0 TRUE 1 'L' 1 2 'i' 2 3 'z' 3 4 '.' 1 5 '1' 4 6 '2' 5 7 '3' 6 8 '@' 1 9 'b' 7 10 'i' 8 11 'g' 9 12 '@' 2 FALSE Starting row: Dots 0, Ats 0, Others 0, Valid TRUE [1] Index and NextChar columns correct, 1 to 12 with 'L' 'i' 'z' '.' '1' '2' '3' '@' 'b' 'i' 'g' '@' [1] Rows 1 to 4: Others 1, 2, 3 and Dots 1 on row 4 [1] Rows 5 to 8: Others 4, 5, 6 and Ats 1 on row 8 [1] Rows 9 to 12: Others 7, 8, 9, Ats 2 and Valid FALSE on row 12 [1] (b)(ii) After the loop, Ats is 2, so the final test makes Valid FALSE (it was already FALSE). Write: FALSE [1] KEY IDEA In a dry run, change one column per step and follow the stop condition exactly; here the second @ ends the loop. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Pseudocode Pro. Tap the picture to open it on YouTube.