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
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
Explanation: Each element from the first stack is popped, then pushed into the second stack; a dequeue operation is then performed on the top of the stack; and finally, each element from the second stack is popped, then pushed into the first stack. As a consequence, each aspect is treated four times.