â Lab
ðïļ Queue â a ring buffer (FIFO, O(1))
FIFO without shifting: a fixed array with head + tail pointers that wrap around. enqueue at tail, dequeue at head, both O(1).
capacity
6
size
3
head
0
tail
3
ring buffer â head dequeues, tail enqueues, both wrap
10
0
head
20
1
30
2
3
tail
4
5
what just happened (say it out loud)
Run an operation to see it step by step.
ėŽė: a ring buffer reuses the same array by moving pointers modulo capacity, so a queue never shifts elements â that's how enqueue/dequeue stay O(1) with fixed memory.
âķ deep-dive videos â âcircular buffer ring buffer queue explainedâ