Past-paper question · 2021 May-June · Paper 42 · Q4(b)(ii)

Question 4(b)(ii) 2021 · May-June · Paper 42 · 5 marks

Original past-paper question for 4(B)(II)
Original past-paper question for 4(B)(II)
Original past-paper question for 4(B)(II)
Reveal official mark-scheme answer Official mark-scheme answer for 4(B)(II)

Official answer for Question 4

Part (b)

(ii)

Question 1

mark per bullet point max 5

Question 5

  • Checking if queue is empty/full …
  • …and returning −1 if empty
✓
(Otherwise)
  • Incrementing HeadIndex …
  • …catching if it goes above 9 and setting to 0
  • Decrement NumberInQueue
  • returning first element
✓
Example pseudocode
✓
FUNCTION Dequeue() RETURNS INTEGER
✓
DECLARE ItemToReturn : INTEGER
✓
IF NumberInQueue = 0
✓
THEN
✓
ItemToReturn ← -1
✓
ELSE
✓
ItemToReturn ← MyNumbers(HeadIndex)
✓
IF HeadIndex = 9
✓
THEN
✓
HeadIndex ← 0
✓
ELSE
✓
HeadIndex ← HeadIndex + 1
✓
ENDIF
✓
NumberInQueue ← NumberInQueue - 1
✓
ENDIF
✓
RETURN ItemToReturn
✓
ENDFUNCTION
✓
9608/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_42.pdf →

Show text version of question

Question 4

Part (b)

(ii)

Question 4

Zara is writing a program to simulate a circular queue.

The queue, MyNumbers, has 10 elements. Enqueue() takes a parameter value and stores it at the tail of the queue. Dequeue()returns the item at the head of the queue.

The current state of the circular queue is:

Index 0 1 2 3 4 5 6 7 8 9

Data 31 45 89 500 23 2

HeadIndex: 2

TailIndex: 8 The global array, MyNumbers, is used to store the positive integer numbers for the queue.

The following global variables are used:

  • HeadIndex stores the index of the first element in the queue
  • TailIndex stores the index of the next free space in the queue
  • NumberInQueue stores the number of items in the queue.

(ii)

The function Dequeue() returns the value at the head of the queue, or −1 if the queue

is empty.

Complete the pseudocode for the function Dequeue().

FUNCTION Dequeue() RETURNS INTEGER

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

ENDFUNCTION

[5]

Question 15

Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Constructs

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_s21_qp_42.pdf

Keep practising this topic