Consider the following case of a queue, where people waiting at a bank cash counter.
Two friends come together and go to the cash counter, i.e. they form a queue - __________ operation is performed two times.
As soon as the person at the front is served, he will be removed from the queue - thus ________ operation is performed. Cashier calls Next to serve the next person who is now at the front of the queue.
Cashier wants to know the length of the queue - size of the _________ is checked.
Meanwhile, a few more people walk in the bank, and three of them join the queue at the cash counter, i.e. ________ happens 3 times.
Another person gets served and leaves the counter, i.e. ________ is performed. Cashier calls Next to serve another person.
The Next three people get served one after another, i.e. _______ is performed thrice.
Cashier calls Next and realises that there are no more people to be served - _________ situation happens.
Identify the correct queue operations for the blank spaces in sequence.
Consider the following case of a queue, where people waiting at a bank cash counter.
Two friends come together and go to the cash counter, i.e. they form a queue - __________ operation is performed two times.
As soon as the person at the front is served, he will be removed from the queue - thus ________ operation is performed. Cashier calls Next to serve the next person who is now at the front of the queue.
Cashier wants to know the length of the queue - size of the _________ is checked.
Meanwhile, a few more people walk in the bank, and three of them join the queue at the cash counter, i.e. ________ happens 3 times.
Another person gets served and leaves the counter, i.e. ________ is performed. Cashier calls Next to serve another person.
The Next three people get served one after another, i.e. _______ is performed thrice.
Cashier calls Next and realises that there are no more people to be served - _________ situation happens.
Identify the correct queue operations for the blank spaces in sequence.
Solution
Joining the queue is enqueue (done twice for the two friends). Serving and removing the front person is dequeue. The cashier checks the size of the queue. Three people joining is enqueue again. One more person served is dequeue, and the next three served is dequeue thrice. Calling Next on an empty queue is underflow, since there is nothing left to remove.
Options 1 and 3: the first blank is wrong, because people joining the queue is enqueue, not dequeue.
Option 4: overflow happens when inserting into a full queue, not when removing from an empty one.
Overflow = adding to a full queue, underflow = removing from an empty queue.
Related questions:
2025: 13 May Shift 2