## 1. A Double-ended queue supports operations such as adding and removing items from both the sides of the queue. They support four operations like addFront(adding item to top of the queue), addRear(adding item to the bottom of the queue), removeFront(removing item from the top of the queue) and removeRear(removing item from the bottom of the queue). You are given only stacks to implement this data structure. You can implement only push and pop operations. What are the total number of stacks required for this operation?(you can reuse the stack)

**A. 1****B. 2****C. 3****D. 4**

**Answer: B**

**Explanation: **

** The addFront and removeFront operations can be performed using one stack itself as push and pop are supported (adding and removing element from top of the stack) but to perform addRear and removeRear you need to pop each element from the current stack and push it into another stack, push or pop the element as per the asked operation from this stack and in the end pop elements from this stack to the first stack.**

## 2. 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**

**Answer: A**

**Explanation: **

** 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).**

## 3. Consider you have an array of some random size. You need to perform dequeue operation. You can perform it using stack operation (push and pop) or using queue operations itself (enQueue and Dequeue). The output is guaranteed to be same. Find some differences?

**A. They will have different time complexities****B. The memory used will not be different****C. There are chances that output might be different****D. No differences**

**Answer: A**

**Explanation:**

** To perform operations such as Dequeue using stack operation you need to empty all the elements from the current stack and push it into the next stack, resulting in a O(number of elements) complexity whereas the time complexity of dequeue operation itself is O(1). And there is a need of a extra stack. Therefore more memory is needed.**

##
4. Consider you have a stack whose elements in it are as follows.
5 4 3 2 << top
Where the top element is 2.
You need to get the following stack
6 5 4 3 2 << top
The operations that needed to be performed are (You can perform only push and pop):

**A. Push(pop()), push(6), push(pop())****B. Push(pop()), push(6)****C. Push(pop()), push(pop()), push(6)****D. Push(6)**

**Answer: A**

**Explanation: **

** By performing push(pop()) on all elements on the current stack to the next stack you get 2 3 4 5 << top.Push(6) and perform push(pop()) you’ll get back 6 5 4 3 2 << top. You have actually performed enQueue operation using push and pop.**

## 5. A double-ended queue supports operations like adding and removing items from both the sides of the queue. They support four operations like addFront(adding item to top of the queue), addRear(adding item to the bottom of the queue), removeFront(removing item from the top of the queue) and removeRear(removing item from the bottom of the queue). You are given only stacks to implement this data structure. You can implement only push and pop operations. What’s the time complexity of performing addFront and addRear? (Assume ‘m’ to be the size of the stack and ‘n’ to be the number of elements)

**A. O(m) and O(n)****B. O(1) and O(n)****C. O(n) and O(1)****D. O(n) and O(m)**

**Answer: B**

**Explanation:**

**addFront is just a normal push operation. Push operation is of O(1). Whereas addRear is of O(n) as it requires two push(pop()) operations of all elements of a stack.**

## 6. Why is implementation of stack operations on queues not feasible for a large dataset (Asssume the number of elements in the stack to be n)?

**A. Because of its time complexity O(n)****B. Because of its time complexity O(log(n))****C. Extra memory is not required****D. There are no problems**

**Answer: A**

**Explanation:**

** To perform Queue operations such as enQueue and deQueue there is a need of emptying all the elements of a current stack and pushing elements into the next stack and vice versa. Therfore it has a time complexity of O(n) and the need of extra stack as well, may not be feasible for a large dataset.**

## 7. Consider yourself to be in a planet where the computational power of chips to be slow. You have an array of size 10.You want to perform enqueue some element into this array. But you can perform only push and pop operations .Push and pop operation both take 1 sec respectively. The total time required to perform enQueue operation is?

**A. 20****B. 40****C. 42****D. 43**

**Answer: D**

**Explanation:**

** First you have to empty all the elements of the current stack into the temporary stack, push the required element and empty the elements of the temporary stack into the original stack. Therfore taking 10+10+1+11+11= 43 seconds.**

## 8. You have two jars, one jar which has 10 rings and the other has none. They are placed one above the other. You want to remove the last ring in the jar. And the second jar is weak and cannot be used to store rings for a long time.

**A. Empty the first jar by removing it one by one from the first jar and placing it into the second jar****B. Empty the first jar by removing it one by one from the first jar and placing it into the second jar and empty the second jar by placing all the rings into the first jar one by one****C. There exists no possible way to do this****D. Break the jar and remove the last one**

**Answer: B**

**Explanation:**

** This is similar to performing dequeue operation using push and pop only. Elements in the first jar are taken out and placed in the second jar. After removing the last element from the first jar, remove all the elements in the second jar and place them in the first jar.**

** **

## 9. Given only a single array of size 10 and no other memory is available. Which of the following operation is not feasible to implement (Given only push and pop operation)?

**A. Push****B. Pop****C. Enqueue****D. Returntop**

**Answer: C**

**Explanation:**

** To perform Enqueue using just push and pop operations, there is a need of another array of same size. But as there is no extra available memeory, the given operation is not feasible.**

## 10. Given an array of size n, let’s assume an element is ‘touched’ if and only if some operation is performed on it(for example, for performing a pop operation the top element is ‘touched’). Now you need to perform Dequeue operation. Each element in the array is touched atleast?

**A. Once****B. Twice****C. Thrice****D. Four times**

**Answer: D**

**Explanation:**

** First each element from the first stack is popped, then pushed into the second stack, dequeue operation is done on the top of the stack and later the each element of second stack is popped then pushed into the first stack. Therfore each element is touched four times.**

- TOP 10 EXAM NEET MCQs on Root Modifications
- Carbon Cycle [TOP 10 EXAM NEET MCQ’s ]
- LATEST NEET MCQ’S ON Chromosome Structure [TOP 10 SOLVED]
- LATEST NEET MCQs on Paramecium
- [TOP 10+] NEET EXAM MCQs on Kranz Anatomy
- Physics NEET EXAM MCQ’s on AC generator [ NEWLY ADDED]
- Conservation of Linear Momentum and Impulse NEET MCQ’s [ NEW ]
- 300+ Solved Most Asked MCQ’s on Highway Engineering