AI Glossary / Graphs and symbolic AI / Beginner
FIFO queue
Definition
A FIFO queue is a collection in which items are removed in the order they were added. FIFO stands for first in, first out. New items join the back, and the oldest remaining item leaves from the front. It is a basic data structure used in scheduling, buffering and search algorithms.
What it means
The queue defines an ordering rule, not what the items mean. Its contents might be requests, messages, documents awaiting processing or search nodes awaiting expansion. Enqueue adds an item; dequeue removes and returns the front item. A peek or front operation inspects that item without removing it.
FIFO order is different from priority order. An urgent item does not jump ahead merely because it is important. It is also different from a stack, where the most recently added item is removed first. Which behavior is appropriate depends on the application rather than one structure being universally preferable.
How it works
An implementation keeps track of the front and back of the collection. A linked structure or circular buffer can support efficient insertion at the back and removal at the front. A naive array implementation that physically shifts all remaining elements after each removal can be much more expensive.
The system must define what happens when an empty queue is read or a bounded queue is full. It might return a special result, raise an error, wait, reject new work or apply a documented overflow policy. Those behaviors are additional choices around the FIFO rule.
With concurrent producers or consumers, synchronization is needed to establish a valid ordering of accepted operations. Removing work in FIFO order does not guarantee completion in that order when several workers run at different speeds. Retry, cancellation and message-delivery behavior also require explicit rules beyond the abstract queue definition.
Three practical examples
1. A document-processing service places accepted files in a FIFO queue. A worker takes the oldest waiting file next, giving a clear ordering rule for otherwise equivalent jobs.
2. Breadth-first graph search uses a FIFO frontier so earlier-discovered levels are expanded before deeper levels. With appropriate visited-state handling, this supports shortest-path search in an unweighted graph.
3. A data collector buffers readings while a consumer processes them. A FIFO queue preserves the accepted sequence, although timestamp ordering across multiple sources may need additional logic before insertion.
Think of it this way
Think of a single orderly line at a service counter: a new arrival joins the back, and the person waiting longest is served next. The analogy explains removal order. It becomes incomplete when several counters operate in parallel, because the first person called may take longer to finish than someone called later. Queue order and completion order are separate properties.
Worked example
Start with an empty queue and write its contents from front to back. Enqueue A, then B, then C: the queue becomes [A, B, C]. Dequeue returns A and leaves [B, C]. Enqueue D: the queue is now [B, C, D]. The next dequeue must return B, leaving [C, D].
Now consider two workers. Worker 1 takes A at time zero and needs ten time units. Worker 2 takes B immediately afterward and needs one time unit. B can finish before A even though both removals respected FIFO ordering. A system requiring ordered publication of results needs an additional mechanism to hold B's output until the preceding result is ready.
Finally, if the waiting queue's capacity is two, [C, D] is full. Attempting to enqueue E requires the defined full-queue policy; FIFO alone does not say whether E should wait, be rejected or cause another action. The example separates ordering, parallel execution and capacity rather than treating them as one promise.
Illustrative case study
Fictional case study: Pine Documents introduces a queue for incoming files and tells users that results will appear in arrival order. Its workers dequeue correctly, but small files finish before large files that arrived earlier. The published promise therefore exceeds what the queue actually guarantees.
The team clarifies whether users need ordered starts, ordered completion or simply progress visibility. It then designs the result-handling behavior around that requirement and defines what happens when capacity is reached. The scenario illustrates requirements clarification, without claiming that a particular design increased throughput or eliminated delays.
Common misconceptions and mistakes
FIFO is not a guarantee of low waiting time. A long-running job can delay later work, and if arrivals persistently exceed processing capacity, the backlog can grow or overflow. Ordering also does not establish exactly-once processing: a worker can fail after receiving an item.
Do not confuse wall-clock arrival at different machines with the order accepted by a particular queue. Simultaneous or delayed messages need a defined ordering point. Finally, deleting an arbitrary middle item or promoting an urgent item may be a useful application feature, but it extends the basic FIFO behavior and should be described explicitly.
Business use
FIFO is useful when accepted arrival order is an appropriate and understandable service rule. Define the scope of that order: one queue, one customer, one partition or a whole system. Then decide capacity, overflow behavior, worker concurrency and recovery rules.
Monitor queue length and waiting time alongside processing throughput. These measures distinguish a slow worker from an overloaded intake process. If some tasks require different urgency or isolation, consider a documented scheduling policy rather than pretending a single FIFO queue handles every priority fairly. Match user-facing promises to the guarantees of the entire processing pipeline.
People also ask
Is FIFO the same as first come, first served?
They express the same basic ordering idea, but a complete service system includes execution, failures and completion behavior beyond the queue itself.
Does a FIFO queue need an array?
No. Several representations can implement the same abstract behavior, including linked structures and circular buffers.
Can a FIFO queue have multiple workers?
Yes, with suitable synchronization. The order of removal can remain FIFO even when completion order differs.
Check your understanding
After enqueueing A, B and C, removing A, and enqueueing D, which item is next?
Answer: B. It is the oldest remaining item. D joins behind both B and C, regardless of how quickly D might be processed.
Related terms
- Queue
- Priority queue
- Breadth First Search
- Scheduling
- enqueue
- dequeue
- stack
- circular buffer
- backpressure
- concurrency
Learn next
Trace enqueue and dequeue operations by hand, then compare a queue with a stack on the same inputs. Next examine how breadth-first search uses FIFO ordering and how a bounded worker queue handles overload and retries.
More in Graphs and symbolic AI
- Factoring - Factoring, in automated logical reasoning, is an inference rule that combines literals of the same sign within one clause when a substitution makes them...
- Feed-forward network - A feed-forward network is a neural network whose prediction computation moves through a directed structure without recurrent cycles.
- Fibonacci search technique - The Fibonacci search technique locates a value in a sorted array by using Fibonacci numbers to choose successive comparison positions.
- Fine-motion planning - Fine-motion planning is the design of robot motion strategies for precise tasks where contact, sensing and positioning uncertainty matter.
- Finger search - Finger search is searching an ordered collection from a known nearby position, called a finger, rather than always starting from the collection's global...
- Finger search tree - A finger search tree is an ordered tree data structure designed to search efficiently from a reference to an existing element, called a finger.
Sources
Primary reference: Paul E. Black, NIST Dictionary of Algorithms and Data Structures, “queue”: https://xlinux.nist.gov/dads/HTML/queue.html . The definition establishes the FIFO operations. The worker timing example and fictional case are original explanations that distinguish the abstract data structure from wider service guarantees.
Previous: Field experiment Next: Filled pause