Skip to main contentSkip to solution

What is the time complexity of inserting an element into a queue which is implemented using an array?

Solution

✅ Correct Option: 1

Inserting (enqueue) into an array-based queue only needs the rear index. The element is placed at the rear position and the rear pointer is incremented, as in rear=rear+1\text{rear} = \text{rear} + 1 followed by Q[rear]=x\text{Q[rear]} = x. No other element is shifted or traversed, so the time taken does not depend on nn and is O(1)\boxed{O(1)}.


Option 4: O(n)O(n) is the cost of dequeue only if the array is kept packed by shifting every element left after each removal, or of enqueue only if the whole array has to be copied when it is full. Neither is part of a normal enqueue.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question