1. Both operations can be performed in O(1) time
  2. At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω(n) 
  3. The worst-case time complexity for both operations will be Ω(n)
  4. Worst case time complexity for both operations will be Ω (log n)
4 views

1 Answers

Option 1 : Both operations can be performed in O(1) time

When we consider a normal implementation of the queue using an array, in that case for enqueue and dequeue operation, we have to shift every other element.  In this, every time we remove the item from the start of the queue, all of the rest of the items in the queue move down by one to fill the space made by the removal of other items.

But if we consider the circular array implementation of a queue, in this case, both enqueue and dequeue can be performed in O(1) time.

Diagram

[ alt="F2 R.S Madhu 17.12.19 D4" src="//storage.googleapis.com/tb-img/production/19/12/F2_R.S_Madhu_17.12.19_D4.png" style="width: 658px; height: 405px;">

4 views

Related Questions