Queue
Also called: FIFO
A collection where the first element added is the first one removed (first in, first out).
Definition
A queue adds elements at the back and removes them from the front, both in O(1). It is used for tasks processed in arrival order, message passing and breadth-first search, which explores a graph level by level. Kotlin and Java use ArrayDeque; Swift has Deque in the swift-collections package. Removing from the front of a plain array is O(n), so it is not a good queue.
In practice
Breadth-first search puts the start node in a queue, then repeatedly takes the front node and adds its unvisited neighbors to the back.
Learn it in context
Lessons that use this term.