9618/32/O/N/23 question 6: worked solution (October/November 2023, paper 32)
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. Q25 9618/32/O/N/23 original Q6 Structured · 7 marks Worked solution (a) Push values; at an operator pop two, calculate, push the result. a = 20, b = 3, c = 10, d = 5. Item read Stack (bottom → top) a 20 b 20, 3 * 60 2 60, 2 / 30 c 30, 10 d 30, 10, 5 / 30, 2 * 60 20 and 3 pushed, then 60 after * [1] 2 pushed, then 30 after / [1] 10 and 5 pushed, then 2 after / [1] Final multiplication gives 60 [1] Marks are given for correct stack stages like these. (b) The RPN expression is read from left to right , one item at a time. [1] Each item is checked: a value is pushed onto the stack until an operator is found. [1] The operator is applied to the last two values (popped), and the result is pushed back. This repeats until one value is left: the answer. [1] KEY IDEA Push values and apply each operator to the top two stack items until one value is left. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by TEACHING BY SM. Tap the picture to open it on YouTube.