What happens if you try to dequeue from an empty queue ?

2024

What happens if you try to dequeue from an empty queue ?

Answer: B. It throws an error or exception.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…

  1. A.

    It returns the last element added.

  2. B.

    It throws an error or exception.

  3. C.

    It returns a special value indicating emptiness.

  4. D.

    It dequeues the next element, regardless of emptiness.

Attempted by 384 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.

Explore the full course: Niacl Ao It Specialist

Loading lesson…