Question bank › A-level Computer Science › Fundamentals of data structures

Queues and stacks

Answer on paper first, then reveal the mark scheme one mark at a time.

1Standard5 marks

A circular queue is implemented using an array Q with six elements, indexed 0 to 5, and the variables front, rear and size. Initially the queue is empty with front = 0, rear = -1 and size = 0.

When an item is added, rear is updated using rear ← (rear + 1) MOD 6; when an item is removed, front ← (front + 1) MOD 6.

The following operations are carried out in order:

Enqueue(A), Enqueue(B), Enqueue(C), Enqueue(D), Dequeue, Dequeue, Enqueue(E), Enqueue(F), Enqueue(G)

(a) State the values of front, rear and size after these operations. [3]

(b) State the item stored at index 0 of the array. [1]

(c) Explain why a circular queue is a more efficient use of memory than a linear queue implemented in a fixed-size array. [1]

2Standard5 marks

A stack is implemented using an array and a top pointer. The array has indices 0 to 4. Initially the stack is empty and the top pointer is −1.

The following operations are carried out in order. Each value removed by POP is output.

PUSH(7), PUSH(3), POP, PUSH(9), PUSH(4), POP, POP, PUSH(2), PUSH(8)

(a) State the values that are output, in order. [2]

(b) State the contents of the stack, from bottom to top, and the value of the top pointer after all of the operations. [2]

(c) Describe the check that the PUSH operation should make before adding an item, and what should happen if the check fails. [1]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session