edited by
501 views
4 votes
4 votes

Consider a STACK being implemented using two QUEUES by favoring the PUSH operations to POP. If $k$ PUSH operations and $l$ POP operations are done on this STACK with $n$ elements initially $(k,l << n)$, the minimum sum of the corresponding ENQUEUE and DEQUEUE operations will be

  1. $O(kl)$
  2. $O(ln)$
  3. $O(k+l)$
  4. $O(k)$
edited by

1 Answer

Best answer
9 votes
9 votes
While we implement a STACK by a QUEUE, we can make either the PUSH or POP operation $O(1)$ and the other will be $O(n).$ Here, PUSH operation is being favored and so it will be $O(1)$ and POP will be $O(n).$

So, after $k$ PUSH and $l$ POP operations, total operations will be $O(k) + O(ln) = O(ln)$ since $(k << n).$
selected by
Answer:

Related questions

1 votes
1 votes
1 answer
1
1 votes
1 votes
1 answer
2
gatecse asked Aug 9, 2020
185 views
What is the value of the postfix expression $8 \ 7 \ 2 \ 4 \ + \ – \ *?$:
1 votes
1 votes
1 answer
3
gatecse asked Aug 9, 2020
278 views
The data structures most suitable to do an inorder and level order traversals of a binary tree respectively areStack and QueueQueue and StackStack and StackQueue and Queu...
1 votes
1 votes
1 answer
4
gatecse asked Aug 9, 2020
160 views
The prefix form of $A/B- (C * D * E)$ is?$-/* * ABCDE$$-/ABCD DE$$-/AB CDE$$-A/BC*DE*$