What is Queue Foundation
A queue serves the value that has been waiting the longest. New values join at the rear. The front is the next one to leave.
Approach
Visualization & algorithm
The finished picture is on screen when the page opens. Next and Play start from the first step. The controls sit under the picture and the pseudocode.
Complexity
| Piece | Cost | Why |
|---|---|---|
| Enqueue or dequeue | O(1) | With a real deque, either end is constant time. |
| Space | O(n) | Every waiting value is stored. |
Implementation
from collections import deque q = deque() q.append(1) # enqueue q.append(2) front = q[0] # front q.popleft() # dequeue