Zeel Mehta
Zeel Mehta

Reputation: 3

If Queue is implemented using an array, then what will be it's worst case time complexity and how?

Queue is implemented using an array. I need WORST CASE time complexity, So, I thought Enqueue will be O(1) and Dequeue will be O(n) because maybe element can be at the end of an array so it will take O(n) complexity to reach their and delete that element. Is this logic correct?

Upvotes: 0

Views: 2201

Answers (1)

user6f6e65
user6f6e65

Reputation: 146

No it will be O(1) you're effectively just changing the pointer to the last element to the one before it. Your queue should never search to find the end only contain a pointer to the last element.

Upvotes: 1

Related Questions