Skip to content
Computer Science · 12th Grade · Object-Oriented Design and Data Structures · Weeks 10-18

Queues: FIFO Data Structure

Students implement queue data structures and understand their use in task scheduling and breadth-first traversals.

Common Core State StandardsCSTA: 3B-AP-12CSTA: 3B-AP-14

About This Topic

Queues model one of the most fundamental principles in computing and daily life: fairness through first-in, first-out ordering. In 12th-grade computer science, students implement queue data structures and connect them to real applications including operating system process scheduling, printer management, network packet routing, and breadth-first graph traversal. CSTA standards 3B-AP-12 and 3B-AP-14 tie this work to both algorithm design and data structure implementation, grounding abstract concepts in practical system design.

Students learn to implement queues using arrays, including circular array techniques to handle the wraparound problem, and linked lists, comparing the trade-offs of each. A naive array-based queue suffers from wasted space as elements are dequeued, requiring a circular index strategy or periodic compaction. A linked-list-based queue eliminates this issue at the cost of per-node memory overhead. Understanding these implementation details prepares students for systems design discussions in college courses and technical interviews.

Queues are excellent for active learning because their real-world equivalent is immediately relatable to students. Acting out a checkout line, a printer job queue, or a CPU scheduler makes the abstract FIFO principle instantly clear, significantly reducing the cognitive load when students transition to the coding implementation.

Key Questions

  1. Compare the operational principles of stacks and queues and their respective use cases.
  2. Design a system where a queue would be the most appropriate data structure for managing tasks.
  3. Evaluate the performance characteristics of array-based versus linked-list-based queue implementations.

Learning Objectives

  • Compare the time complexity of enqueue and dequeue operations for array-based and linked-list-based queue implementations.
  • Design a program that utilizes a queue to manage print jobs for a simulated network printer.
  • Analyze the role of queues in implementing breadth-first search algorithms for graph traversal.
  • Evaluate the trade-offs between space efficiency and time efficiency for different queue implementations.

Before You Start

Arrays and Linked Lists

Why: Students need a foundational understanding of how arrays and linked lists store data to implement and compare queue variations.

Stacks: LIFO Data Structure

Why: Comparing queues to stacks helps students solidify the FIFO versus LIFO principles and their distinct applications.

Basic Algorithm Analysis (Big O Notation)

Why: Understanding Big O notation is essential for evaluating the performance characteristics of different queue implementations.

Key Vocabulary

QueueA linear data structure that follows the First-In, First-Out (FIFO) principle, where elements are added at one end (rear) and removed from the other end (front).
EnqueueThe operation of adding an element to the rear of the queue.
DequeueThe operation of removing and returning the element from the front of the queue.
FIFOAcronym for First-In, First-Out, meaning the first element added to a data structure is the first one to be removed.
Circular ArrayAn array implementation of a queue where the indices wrap around, allowing efficient reuse of space and avoiding shifting elements.

Watch Out for These Misconceptions

Common MisconceptionQueues and stacks can be used interchangeably since both store sequences of items.

What to Teach Instead

The order in which items are removed is fundamentally different. Using a stack where a queue is needed produces incorrect behavior. For example, replacing the queue in BFS with a stack transforms the algorithm into depth-first search, a completely different traversal with different properties. The structural choice directly determines algorithmic correctness.

Common MisconceptionA simple array-based queue with a front pointer is memory-efficient.

What to Teach Instead

As elements are dequeued, the front of the array advances, leaving wasted space at the beginning. Without a circular buffer or periodic compaction, the array grows without bound even if the logical queue size stays small. Students benefit from tracing the index state of an array queue over many operations to see how unused space accumulates.

Common MisconceptionA queue must always process items in strict arrival order.

What to Teach Instead

Priority queues extend the FIFO concept by assigning a priority to each item, processing higher-priority items first regardless of arrival time. This is essential for systems like hospital triage and CPU scheduling. Understanding this extension helps students see FIFO as one point on a spectrum of ordering policies rather than the only valid queue behavior.

Active Learning Ideas

See all activities

Simulation Game: The Printer Queue

Students act as print jobs arriving at different times. The 'printer' (one designated student) processes jobs strictly in arrival order. After one round, introduce a priority variant where urgent jobs jump ahead. The class compares the two systems, discussing fairness, throughput, and starvation, making the design trade-offs tangible before they appear in code.

25 min·Whole Class

Collaborative Lab: Array-Based vs. Linked-List Queue

Pairs implement both an array-based and a linked-list-based queue with enqueue, dequeue, peek, and isEmpty methods. They benchmark both with a sequence of 1,000 operations and compare memory usage by counting the maximum number of variables in use at once. Pairs then write a brief design recommendation for each of two scenarios: a memory-constrained embedded system and a high-throughput server.

60 min·Pairs

Think-Pair-Share: BFS and Queues

Show students a small graph and ask them individually to trace why a queue (not a stack) ensures that breadth-first search explores nodes level by level. Pairs compare their reasoning and then trace through the BFS algorithm step by step on a shared diagram, annotating the queue state after each enqueue and dequeue operation. This pairs data structure understanding with algorithm application.

30 min·Pairs

Gallery Walk: Real-World Queue Systems

Post 5 real-world queue scenarios: airport check-in, hospital triage, CPU scheduling, message broker, HTTP request handling. For each, student pairs answer three questions: what is the queue storing, what determines order, and what happens if the queue is full or empty. Responses are compared during debrief, emphasizing how each system handles overflow or high-demand situations.

35 min·Pairs

Real-World Connections

  • Operating system schedulers use queues to manage processes waiting for CPU time, ensuring fair allocation and preventing starvation. For example, Windows Task Scheduler uses queues to handle background tasks.
  • Customer service call centers often employ queues to manage incoming calls, directing them to the next available agent. Companies like Amazon use such systems to manage customer interactions efficiently.
  • Network routers use queues to buffer data packets before sending them to their destination, managing traffic flow and preventing congestion. This is critical for the stability of the internet.

Assessment Ideas

Quick Check

Present students with a sequence of enqueue and dequeue operations on a queue. Ask them to trace the state of the queue after each operation and identify the element that will be dequeued next. Example: Given enqueue(A), enqueue(B), dequeue(), enqueue(C), dequeue(), what is the next element to be dequeued?

Discussion Prompt

Pose the following scenario: 'Imagine you are designing a system for a busy coffee shop. Customers place orders, and the barista makes them in the order they arrive. Which data structure, a stack or a queue, would be most appropriate for managing these orders, and why? Describe the enqueue and dequeue operations in this context.'

Exit Ticket

Ask students to write down one specific advantage of using a linked-list-based queue over an array-based queue, and one specific advantage of an array-based queue over a linked-list-based queue. They should also briefly explain why they chose these advantages.

Frequently Asked Questions

What is the difference between a queue and a priority queue?
A standard queue processes items in strict arrival order (FIFO). A priority queue processes items based on a priority value, with higher-priority items dequeued first regardless of when they arrived. Priority queues are typically implemented with heaps rather than simple arrays or linked lists, enabling efficient O(log n) insertion and removal.
How does active learning support understanding of queue data structures?
Acting out real queues like printer jobs, checkout lines, or CPU processes makes the FIFO principle and its edge cases tangible before students write a single line of code. Simulation activities also surface the natural questions students need to solve in implementation, such as what happens when a queue is empty and someone tries to dequeue.
Where are queues used in real operating systems?
Operating systems use queues extensively: the ready queue holds processes waiting for CPU time, I/O queues manage devices waiting to be serviced, and the scheduler picks the next process to run using queue-based policies. Message brokers like Kafka and RabbitMQ are essentially very large, persistent queues for distributed systems.
What is a circular buffer and why is it used for queues?
A circular buffer treats a fixed-size array as if it wraps around, using modular arithmetic to reuse space freed by previous dequeues. The front and rear indices advance around the array, allowing indefinite enqueue and dequeue operations without array shifting or growing. This makes array-based queues practical for fixed-capacity scenarios like network buffers.