# You are asked to perform a queue operation using a stack. Assume the size of the stack is some value ‚Äòn‚Äô and there are ‚Äòm‚Äô number of variables in this stack. The time complexity of performing deQueue operation is (Using only stack operations like push and pop)(Tightly bound).

+1 vote
You are asked to perform a queue operation using a stack. Assume the size of the stack is some value ‚Äòn‚Äô and there are ‚Äòm‚Äô number of variables in this stack. The time complexity of performing deQueue operation is (Using only stack operations like push and pop)(Tightly bound).

(a) O(m)

(b) O(n)

(c) O(m*n)

(d) Data is insufficient

+1 vote
by (679k points)
selected by

Right option is (a) O(m)

The best I can explain: To perform deQueue operation you need to pop each element from the first stack and push it into the second stack. In this case you need to pop ‚Äòm‚Äô times and need to perform push operations also ‚Äòm‚Äô times. Then you pop the first element from this second stack (constant time) and pass all the elements to the first stack (as done in the beginning)(‚Äòm-1‚Äô times). Therfore the time complexity is O(m).

+1 vote
+1 vote
+1 vote
+1 vote
+1 vote
+1 vote
+1 vote
+1 vote
+1 vote
+1 vote