611 views
1 votes
1 votes
Consider the following operation along wit he queue and dequeue operation on queue,where k is global parameter

multidequeue(q)

{

m=k

while(q is not empty and m>o)

{

dequeue(q)

m=m-1

}}

worst time complexity of a sequence of n multidequeue() operations on initially empty queue

A)theta(n)

b)theta(n+k)

c)theta(n^2)

d)theta(nk)

2 Answers

5 votes
5 votes
Since initially Q is empty while loop wil never execute Ok.Now since operation multideque is performed n times.so overall time complexity would be theta(n).
0 votes
0 votes
Since initially queue is empty and while loop will not execute and since the function calling n times with constant time 1 answer should be theta(nk)

No related questions found