What happens if you try to dequeue from an empty queue ?
2024
What happens if you try to dequeue from an empty queue ?
- A.
It returns the last element added.
- B.
It throws an error or exception.
- C.
It returns a special value indicating emptiness.
- D.
It dequeues the next element, regardless of emptiness.
Attempted by 132 students.
Show answer & explanation
Correct answer: B
A queue removes elements from the front using the dequeue operation. If the queue is empty, there is no front element to remove, so the operation results in a queue underflow condition. In most implementations this is handled by throwing an error or exception, or otherwise reporting the underflow.