MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How many Queues are required to implement a Stack?
A
2
B
3
C
1
D
4
Explanation: 

Detailed explanation-1: -Explanation: A stack can be implemented using two queues.

Detailed explanation-2: -Detailed Solution. A stack can be implemented using two queues.

Detailed explanation-3: -Using 2 queues, we can make a stack, which can perform push operations in O(n) and all other functionalities in O(1) time. Let the queues be called firstQ and secondQ. We will ensure that the pop operation will only pop from the firstQ. secondQ is used to put every new element to the front of firstQ.

Detailed explanation-4: -In computer science, a stack is an abstract data type that serves as a collection of elements, with two main operations: Push, which adds an element to the collection, and. Pop, which removes the most recently added element that was not yet removed.

There is 1 question to complete.