9618/31/M/J/24 question 5: worked solution (May/June 2024, paper 31)
Show as plain textHide plain text
Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software Worked solution from the System Software Paper 3 Advanced Theory booklet, Part 2 of 2. Q26 9618/31/M/J/24 original Q5 Structured · 9 marks Worked solution (a) Turn each operator into brackets in order. 5 2 + becomes (5 + 2); 9 3 - becomes (9 - 3). [1] Then / joins them: (5 + 2) / (9 - 3). [1] Then * 3: ((5 + 2) / (9 - 3)) * 3 [1] (b) Do the brackets first, then the operator that joins them. (7 + 3) becomes 7 3 + [1] (2 * 8) becomes 2 8 *, then - and 6 /: 7 3 + 2 8 * - 6 / [1] (c) a = 17, b = 5, c = 7, d = 3, e = 10. Item read Stack (bottom → top) a 17 b 17, 5 - 12 c 12, 7 d 12, 7, 3 + 12, 10 * 120 e 120, 10 / 12 17 and 5 pushed, then 12 after - [1] 7 and 3 pushed, then 10 after + [1] 120 after * [1] 10 pushed, then final answer 12 after / [1] Marks are given for correct stack stages like these. KEY IDEA Convert RPN by joining the top two items with each operator, and evaluate it using a stack. TOTAL 9 marks Official mark scheme VIDEO ▶ Starts at Q5 (30:16) Starts at Q5 (30:16) · by Pseudocode Pro. Tap the picture to open it on YouTube.