Quelpr

CAPE Computer Science Unit 2 · 2014 · Paper 2 · Question 1(b)(i)

In a searching application, the procedures Add or Mult pop the stack twice, add or multiply the popped values respectively, and push the result back onto the stack. Given X = 1, Y = 2, Z = 3, and W = 4.

Determine the contents of the stack following the given sequence of procedure calls, showing all steps involved: Push(Stack, X), Push(Stack, Y), Add(Stack), Push(Stack, Z), Push(Stack, W), Mult(Stack), Add(Stack).

The mark scheme is shown once you've answered.

Practise this question

Other parts of this question

  1. 1(a)(i)State whether a stack must exist prior to executing CreateStack.[1 mark]
  2. 1(a)(ii)State whether a stack must exist prior to executing DestroyStack.[1 mark]
  3. 1(b)(ii)State ONE condition that must exist for the Add and Mult procedures to work effectively.[1 mark]
  4. 1(b)(iii)Explain what will happen to the stack if the ADD operation is continuously applied to it.[2 marks]
  5. 1(c)(i)Explain the purpose of Enqueue() and Dequeue() in a FIFO queue.[5 marks]
  6. 1(c)(ii)Write an algorithm CountQueue using only the standard queue Abstract Data Type (ADT) operations that returns an integer count of the elements in the queue.[8 marks]

More practice: the rest of this paper · more Abstract Data Types (ADTs) questions · all CAPE Computer Science Unit 2 past papers