9618/31/M/J/21 question 4: worked solution (May/June 2021, 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. Q15 9618/31/M/J/21 original Q4 Structured · 8 marks Worked solution (a)(i) Write any two of these: RPN is an unambiguous way of writing an expression [1] It is read from left to right [1] It needs no brackets It needs no rules of precedence (no BODMAS) Only two of these points can score (2 marks). (a)(ii) Name the structure, then give a reason: A stack [1] Operands are pushed on, and when an operator is read the top two are popped in the reverse order to how they were pushed [1] A binary tree also scores for the structure, with the reason that tree traversal lets both infix and postfix be evaluated. (b) Do the brackets first: (a – b) gives a b –, (a + c) gives a c +. Multiply them, then divide by 7. Write: a b - a c + * 7 / [1] (c) Work along the RPN, joining the last two items with each operator: a b / gives a / b; then * 4; then a b + gives (a + b); then the final – joins them. Write: a / b * 4 - (a + b) [1] (d) Rewrite the RPN as infix and put in the values. Correct structure: (a + b) / (c / d) [1] Correct substitution: (17 + 3) / (48 / 12) [1] = 20 / 4 = 5 KEY IDEA RPN needs no brackets or precedence rules because the order of the operators gives the order of working, and a stack evaluates it. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.