Multiple choice time complexity of queue

If queue is implemented using arrays, what would be the worst run time complexity of queue and dequeue operations?

  1. $O(n), O(1)$
  2. $O(1), O(1)$
  3. $O(1), O(n)$
  4. $O(n), \theta(1)$
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

A queue implemented with an array using front and rear pointers allows both enqueue and dequeue operations to be performed in O(1) time.

AI explanation

When a queue is implemented as a circular array with separate front and rear indices, both enqueue and dequeue simply write/read at an index and advance a pointer — no shifting of other elements is required, so both operations run in constant O(1) time even in the worst case. This is why circular-array (or ring-buffer) implementations are preferred over naively shifting all elements on dequeue, which would cost O(n).