Algorithms and Data Structures · Senior · Question 60 of 75
What problem does a ring buffer with head and tail indices solve for a high-throughput queue?
- 1Unlimited capacity without ever losing any data
- 2Automatic sorting of the queued elements
- ✓Correct answer: O(1) enqueue and dequeue without shifting
Explanation
Indices wrap around with % capacity, so the buffer is reused forever. It's how audio buffers, network drivers and log collectors queue data. When full, it either blocks, drops new items or overwrites the oldest.