Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software

Q17 · 9618/31/M/J/22 Q5

Worked solution from the System Software Paper 3 Advanced Theory booklet, Part 2 of 2.

Q179618/31/M/J/22original Q5Structured · 12 marks
Question 5 from 9618/31/M/J/22

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 readStack (bottom → top)
m10
m10, 10
j10, 10, 3
k10, 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 IDEAPush operands; when an operator comes, pop two, calculate and push the result back.
TOTAL 12 marks

Official mark scheme

Mark scheme for 9618/31/M/J/22 question 5
VIDEO
▶ Whole paper

Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.