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
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
Explanation: To perform operations like Dequeue using stack operations, you must empty all of the elements from the current stack and transfer them into the next stack, resulting in an O(number of elements) complexity, while the time complexity of the dequeue operation is O(number of elements) (1). There is also a need for an additional stack. As a result, more memory is needed.