QUESTION 50 Which type of queue given in options will give an "overflow" error even if it...
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
QUESTION 50
Which type of queue given in options will give an "overflow" error even if it has few slots empty at the beginning(FRONT) of the queue?
Show answer & explanation
A simple queue uses a linear data structure where elements are added at the REAR and removed from the FRONT. Even if slots exist at the beginning after dequeuing, a simple queue cannot reuse that space because REAR pointer only moves forward. This causes overflow when REAR reaches the end, regardless of empty slots at the front. In contrast, a circular queue wraps around and reuses empty front space, a priority queue manages overflow by priority handling, and a deque allows insertion/deletion from both ends with better space utilization.
Step-by-step Derivation:
Simple queue overflow scenario: Consider a simple queue with capacity 5:
- Enqueue A, B, C, D, E → Array: [A, B, C, D, E], REAR=5, FRONT=1
- Dequeue twice → Array: [_, _, C, D, E], REAR=5, FRONT=3 (2 empty slots at front)
- Try to enqueue F → REAR (5) == capacity, overflow error occurs even though indices 0-1 are empty
- REAR pointer cannot move backward or wrap; it only increments → wasted space at front
Circular queue: Would wrap REAR back to 0, reusing empty space.
Deque: Allows front insertions, utilizing empty space.
Priority queue: Manages ordering differently; overflow depends on implementation.