166k views
2 votes
Consider a QUEUE implemented by array, and containing N elements. The DEQUE operation has worst case time complexity of...

a. O(1)
b. O(log N)
c. O(N)
d. O(N²)

1 Answer

7 votes

The DEQUE operation in a queue implemented by an array has a worst-case time complexity of O(N) because it may require shifting all N elements in the array when the first element is removed.

When considering the worst-case time complexity of a DEQUE operation in a queue implemented by an array containing N elements, it's crucial to understand what a DEQUE operation entails. A DEQUE operation involves removing an element from one end of the queue. In the case of an array, this often means removing the first element, which requires shifting all other elements one position forward to fill the gap left by the dequeued element.

In the worst case, every element might need to be moved, which occurs when the dequeued element is the first element in a non-circular queue implemented by an array. Therefore, the worst-case time complexity of a DEQUE operation in such a queue is O(N), where N is the number of elements in the queue.

Answer to the student's question:

The DEQUE operation has worst-case time complexity of O(N).

User Aashish Bhatnagar
by
8.3k points