ArticlesLinear structures
Queues
First in, first out. Enqueue at the back, dequeue from the front. Breadth-first search is this rule with vertices as the payload.
A queue serves items in arrival order. Enqueue adds at the back. Dequeue removes from the front. A printer queue, a checkout line, and breadth-first search are the same rule: the thing that has been waiting longest goes next.
A TypeScript array can do this with push and shift. Be honest about the cost. Shift moves every later element, so it is O(n). For the sizes in this course that is fine. A real deque, or two stacks used as a queue, makes both ends O(1). Know the gap, and do not reach for a clever queue until shift shows up in a hot loop.
You will use a queue again, unchanged, when a graph asks for the shortest unweighted path. The structure is the same. Only the payload changes, from a number in a window to a vertex and a distance.