Q1. Minimum In A Stack
In what minimum time complexity you can compute minimum at any state of stack?
O(1)
O(n)
O(n^2)
Q1. Minimum In A Stack
In what minimum time complexity you can compute minimum at any state of stack?
O(1)
O(n)
O(n^2)
Hello @Jun18APP0112,
You can get the minimum element from a stack in O(1) but if you have stored the elements in a certain way.
This has been explained in your course itself.
But, for a normal stack. You need to traverse through each element of the stack in order to find the minimum element. Thus, the time complexity is O(n).
Hope, this would help.
Give a like if you are satisfied.
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 O(n) O(nk) O(n+k) O(n^2)
sorry sir my was this…
Hello @Jun18APP0112,
Since the queue is empty initially, the condition of while loop never becomes true. So the time complexity is \Theta(n).
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.