Reputation: 3
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
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