A queue is implemented using two stacks. Consider the following scenarios for…
A queue is implemented using two stacks. Consider the following scenarios for time complexity of enqueue and dequeue operations:
- A.
If enqueue (push) is O(1), then dequeue (pop) is O(n); if enqueue (push) is O(n), then dequeue (pop) is O(1)
- B.
If enqueue (push) is O(1), then dequeue (pop) is O(1); if enqueue (push) is O(n), then dequeue (pop) is O(n)
- C.
Both enqueue and dequeue are always O(n)
- D.
Both enqueue and dequeue are always O(1)
Attempted by 535 students.
Sign up free to check your answer
Sign up freeLoading lesson…