Questions: Queues

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

You implement a queue using a plain array: enqueue adds to the end, and dequeue removes from the front by shifting all remaining elements left. What is the time complexity of dequeue?

AO(1), because you are only accessing the first element
BO(log n), because the shift operation uses binary search
CO(n), because shifting all remaining elements requires touching each one
DO(1) amortized, because shifts are rare in practice
Question 2 Multiple Choice

A circular buffer has capacity 5 and holds [_, A, B, C, _] with front=1 and rear=4. After one enqueue (D) and two dequeues, what are the new front and rear indices?

Afront=3, rear=0 (rear wrapped around using modular arithmetic)
Bfront=1, rear=5 (rear advanced past the end)
Cfront=3, rear=5 (both advanced without wrapping)
Dfront=0, rear=4 (elements were shifted to fill the gap)
Question 3 True / False

A queue and a stack differ primarily in which end elements are added to — both structures remove elements from the same (front) end.

TTrue
FFalse
Question 4 True / False

Using a linked list with both head and tail pointers to implement a queue allows O(1) enqueue and O(1) dequeue with no fixed-capacity limitation.

TTrue
FFalse
Question 5 Short Answer

Why is a circular buffer the preferred array-based implementation of a queue, and what problem does it solve over a naive array approach?

Think about your answer, then reveal below.