retagged by
1,505 views
4 votes
4 votes
In implementation of queue using stack, deletion of second element from front take Ο(1) time, when insertion take Ο(n) time.
Which of the following is correct ?

True / False
retagged by

1 Answer

Best answer
3 votes
3 votes

By this approach it wil be true--

enQueue(q, x)
  1) While stack1 is not empty, push everything from satck1 to stack2.
  2) Push x to stack1 .
  3) Push everything back to stack1.

dnQueue(q)
  1) If stack1 is empty then error
  2) Pop an item from stack1 and return it
selected by

Related questions

2 votes
2 votes
2 answers
1
3 votes
3 votes
3 answers
2
Ibtisam Sayyad asked Jan 12, 2018
7,864 views
What are the minimum enqueue and dequeue operations needed to perform pop operation for a stack which is implemented with two queues if there are already 10 elements in t...