Suppose an initially empty queue has executed in some order a total of 30 enqueue operations, 10 first operations, and 15 dequeue operations, 5 of which raised EmptyErrors that were caught and ignored. What is the current size of queue?
The current size of the queue is 20
Explanation:
A queue is a linear data structure in which addition is done at the one end and deletion is one at another end.
Insertion can be performed at the rear end.
Deletion can be performed at the front end.
The size of the queue initially is = 0
The size of the queue after 30 enqueue operations is = 30
The size of the queue after 10 first operations is = 30
The first operation doesn't delete the element from the queue. So, the size of the queue will remain the same.
The size of the queue after 15 dequeue operations is = 30 - 15 = 15
But 5 of which raised EmptyErrors, so 5 dequeue operation failed.
The size of the queue after 5 dequeue operation failed = 15 + 5 = 20
Because the failed operation doesn't deleted any element from the queue.
Get Answers For Free
Most questions answered within 1 hours.