First-in, first-out data structure, used for BFS and level-order processing.
1 algorithm3 problems
A queue serves items in the order they arrived. New items join at the rear and leave from the front, like people in a line at a shop. Software leans on this all the time: print jobs, requests waiting for a web server, messages passed between parts of a program, and tasks handed to a pool of workers. In interviews the queue mostly appears inside breadth-first search, which must finish every place one step away before it moves on to anything two steps away.
Fairness by arrival time. Nothing in a queue can skip ahead or be pulled from the middle; enqueue only touches the rear and dequeue only touches the front, so each costs O(1) when the queue is built well. Whatever entered first is always the next to leave, and that fixed order is exactly what makes breadth-first search visit places in rings of growing distance.
The queue is easiest to understand next to its relatives on this site. The Stack section is the mirror image: newest first instead of oldest first, which suits undo and depth-first search. The Heap section covers the priority queue, which ignores arrival order and hands back the smallest or largest value; Meeting Rooms there is a good example. The FIFO cache in the Cache section is a queue with a size limit, evicting whoever arrived first. Once enqueue and dequeue feel natural, read the breadth-first search pages that run on a queue: BFS in the Graph Theory section, level order traversal in Binary Trees, and BFS and Rotting Oranges in the Matrix section; in Rotting Oranges the queue starts with every rotten cell at once. A double-ended queue, which adds and removes at both ends, is the next step up when a problem such as a sliding window maximum needs both.