9618/31/M/J/22 question 5: worked solution (May/June 2022, 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. Q17 9618/31/M/J/22 original Q5 Structured · 12 marks Worked solution (a) Write each bracket in RPN, then the operator between them goes last: (j + k) is j k +, (j – k) is j k –. Write: j k + j k - / j k + [1] j k - / (the second part and the divide) [1] (b)(i) Work along m m j k * - *. A number is pushed. An operator pops the top two, works them out and pushes the result. Values: m = 10, j = 3, k = 2. Operators are never put on the stack. Item read Stack (bottom → top) m 10 m 10, 10 j 10, 10, 3 k 10, 10, 3, 2 * 10, 10, 6 - 10, 4 * 40 First four stacks correct (10; 10, 10; 10, 10, 3; 10, 10, 3, 2) [1] After *: 10, 10, 6 [1] After -: 10, 4 [1] After the last *: 40 [1] (b)(ii) Write four of these steps: Work through the expression from left to right [1] PUSH each number (10/m, 3/j, 2/k) onto the stack as it is read [1] When an operator (the first is *) is reached, POP the top two numbers (2 and 3) [1] Apply the operation to them PUSH the result back onto the stack [1] Continue to the end of the expression; the final value left is the answer Only four points score (4 marks). A purely generic answer without the values scores at most 3. (c) Write any two uses: Recursion (storing return addresses and values) [1] Implementing abstract data types such as linked lists [1] Procedure calls Interrupt handling (storing the contents of registers) Only two score (2 marks). KEY IDEA Push operands; when an operator comes, pop two, calculate and push the result back. TOTAL 12 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.