Maggie HTTN
Data Structures • Beginner Foundation

Queue (Abstract Data Type)

A queue stores items using FIFO — First In, First Out. Items enter at the rear and leave from the front.

Queues are core to many real systems: scheduling, printers, customer service lines, and networking. In algorithms, queues are essential for BFS and many simulations.

This page teaches the queue mental model and the 3 core operations: enqueue, dequeue, and front/peek.

Quick Facts

Access pattern
FIFO (First In, First Out)
Where operations happen
Insert at rear, remove from front
Common operations
enqueue, dequeue, front/peek, isEmpty
Time cost (typical)
enqueue/dequeue/front are O(1)

Beginner Rules

  1. Enqueue: add a new item to the rear (back).
  2. Dequeue: remove the front item (and return it).
  3. Front / Peek: look at the front item without removing it.
  4. Underflow: dequeuing from an empty queue is an error (or returns nothing).
  5. Oldest leaves first: the first item in is the first item out (FIFO).

Stack vs Queue (Easy Comparison)

Stack
LIFO — newest leaves first.
Works like a pile of plates.
Used in recursion + DFS.
Queue
FIFO — oldest leaves first.
Works like a line of people.
Used in BFS + scheduling.

Why It’s Important

Print jobs
Jobs are processed in the order they arrive.
Scheduling
CPU/task scheduling often uses queue-like behavior.
Networking
Packets wait in queues before being transmitted.
BFS reasoning
Breadth-first search explores “level by level” using a queue.

Demo / Media

Animation

This demo visualizes enqueue (rear insertion), dequeue (front removal), and front/peek. Notice how the earliest item added is always the first removed (FIFO).

Common Mistakes (and how to avoid them)

  • Confusing enqueue vs dequeue: enqueue adds to the rear; dequeue removes from the front.
  • Confusing FIFO vs LIFO: queues remove oldest; stacks remove newest.
  • Dequeue on empty queue: always check isEmpty() (or handle underflow).

Outcome

Learners can describe FIFO, correctly apply enqueue/dequeue/front, and recognize queues in real applications like scheduling, networking, BFS, and everyday “line” systems.

UX/UI • Pedagogy • HCI

A short teaching-focused rationale: what I designed, how I structured learning, and the interaction principles behind it.

UX/UI Design
  • Information architecture: definition → rules → comparison → uses → demo.
  • Visual hierarchy: headings + cards chunk content into “one idea per block.”
  • Clear CTA: “Watch Demo” scrolls to the video (low navigation cost).
  • Consistency: same layout pattern across all algorithm pages.
  • Accessibility: readable type/spacing + native video controls + playsinline.

Pedagogy
  • Scaffolded learning: vocabulary first, then operations, then applications.
  • Three-act structure: what it is → how it works → why it matters (+ demo).
  • Cognitive load: short rules + chunking reduces overload for beginners.
  • Contrast cases: stack vs queue side-by-side fixes FIFO/LIFO confusion.
  • Self-check: “Common Mistakes” supports reflection and correction.

HCI Principles
  • Mental models: queue maps to a real-world line (front/rear stays consistent).
  • Recognition over recall: labels + quick facts reduce memorization burden.
  • Error prevention: highlight underflow + operation mix-ups before practice.
  • Feedback cues: demo reinforces cause → effect (enqueue/dequeue outcomes).
  • Usability heuristics: clarity, consistency, and predictable navigation.

Teaching strategy: scaffold → contrast → apply → demonstrate → self-check. This supports beginner confidence while keeping the interface simple and consistent.