Master LIFO and FIFO processing models
Section 6 of 8
From web servers to AI pathfinding, the queue is the backbone of asynchronous processing and level-by-level discovery.
The most famous algorithm that uses a queue. BFS explores a graph **level-by-level**. It visits all neighbors of a node before moving to the next depth.
Start node is ENQUEUED.
Pop front node, ENQUEUE all its unvisited neighbors.
Repeat until queue is empty. Guaranteed shortest path in unweighted graphs.
Level-Order Traversal
Operating systems use queues (specifically Round Robin) to give every running program a slice of CPU time fairly.
When 10 people send documents to one printer, the printer queue ensures the first person's job is finished before starting the next.
Routers use queues to handle bursts of data packets. If data arrives faster than it can be sent, it's queued (buffered).