Solution
The correct answer is option 2.
Explanation:
Operations of Dequeue :
- AddFront : adding item to front of the queue.
- AddRear : adding item to the rear of the queue.
- RemoveFront : removing item from the front of the queue.
- RemoveRear : removing item from the rear of the queue.
Stack has two operations : PUSH - to insert data into stack. POP - to delete an element from stack. It supports LIFO(Last In First Out) .
AddFront() is same as PUSH operation, therefore , the time complexity is O(1).
To perform AddRear() operation, using stack we need two operations , PUSH(POP()) all the elements of the stack. Therefore, the time complexity is O(n).