Quiz Question Multiqueue

How is the worst case complexity calculated in this question?

Q4. Multi Dequeue
Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter.

MultiDequeue(Q){
m = k
while (Q is not empty and m > 0) {
Dequeue(Q)
m = m - 1
}
}
What is the worst case time complexity of a sequence of n MultiDequeue() operations

Since the queue is empty initially, the condition of while loop never becomes true. So the time complexity is O(n).

But in the given question it is not mentioned that queue is empty

Yes it should be mentioned.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.