What will be the answer of this mcq and why?

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

O(n)

O(nk)

O(n+k)

O(n^2)

Hello @Akshita99,

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

Hope, this would help.

but it is nowhere mentioned that the queue is empty

sir plz help clearing the doubt

Hello @Akshita99,

Yes, it is not mentioned. But it is. I would convey the same to your mentors.
They will soon update it.

okay thank you for the help

Hello @Akshita99,

Please, mark it as resolved if you haven’t.