wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following operation along with Enqueue and Dequeue operations on queue where k is a global parameter.

Multi - Dequeue (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 queue operations on an initially empty queue?

A
Θ(n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
Θ(n+k)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Θ(n2)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Θ(nk)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A Θ(n)
Since there are 3 queue operation i.e., enqueue, dequeue and Multi - dequeue.

'n' enqueue operation will take Θ(n) time, 'n' dequeue operation will Θ(n) time, 'n' Multi- dequeue operation will take Θ(n) time i.e., Min (n, k) but for worst case when n = k time complexity will be Θ(n)

flag
Suggest Corrections
thumbs-up
2
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Property 1
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon