Wipro
Company
Programming
Program
What is the minimum number of stacks of size n required to implement a queue of same size??
a) 1
b) 2
3) 3
4) 4
Read Solution (Total 8)
-
- 2 stacks of size n are required to implement same size of queue as stack has LIFO property, so if element 1 is inserted first and element n is inserted last, then element n will be out first as it was the last element but in queue, it follows FIFO so element 1 should come out first. In that case, we take another stack and we pop out element from first stack, element n first popped and inserted in 2nd stack in this way we move and in second stack at the top we will get element 1 so, when we pop element 1 will come first and it was also inserted first in the 1st stack, so we are able to implement FIFO or queue with the help 2 LIFO or stacks.
- 9 years agoHelpfull: Yes(9) No(0)
- answer is two
so option is
(b) - 10 years agoHelpfull: Yes(2) No(2)
- one queue is sufficient for one stack. 1stly pop the elements of stack to the queue then it will goes in reverse order then again push all elements of queue to the empty stack and finally add it to empty queue.. so we need only one queue.
- 9 years agoHelpfull: Yes(2) No(2)
- Option b-2
- 9 years agoHelpfull: Yes(1) No(1)
- ans is 1 bcz if it is more than 1 impossible to build a queue with same size of stacks.
|___| at size 1 both queue and stack are equal. - 9 years agoHelpfull: Yes(1) No(1)
- ans is two..tht is b)
- 9 years agoHelpfull: Yes(0) No(1)
- we need 2 stacks. first keep the item in one stack so the first item will become last one and now take this item one by one and place in other stack .now our goal is achieved the last become fast one fifo.
- 8 years agoHelpfull: Yes(0) No(0)
- a queue required 2 stacks
- 5 years agoHelpfull: Yes(0) No(0)
Wipro Other Question