Claviro

Data Structures

Queues – FIFO Structure

Before You Apply

First observe the behavior in Explore mode, then switch to Apply to test each operation with intent.

Core Idea

A queue is a linear data structure following First-In-First-Out (FIFO) principle. Elements are added at the rear (enqueued) and removed from the front (dequeued).

Observe This First

FIFO (First-In-First-Out): First element added is first to be removed

Then Apply

Print Queue: Documents printed in order received

Queues – FIFO Structure Lab

Elements enter from REAR and leave from FRONT in FIFO order.

Front 0Rear 2

Ready|Waiting for a queue operation

Time: Depends on operation|Space: O(1) auxiliary

Current
Comparing
Correct / Inserted
Removed

Pseudocode

1read front element
2prepare new value at rear
3enqueue value at rear
4mark front for dequeue
5remove front and advance queue
6visit queue from front to rear

Queues are FIFO: the front leaves first, and new values join at the rear.

Explore mode: inspect FRONT and REAR to understand FIFO behavior.

Understanding the Observation

What did you observe?

Enqueue: Add element at rear → O(1)

Why did this happen?

FIFO (First-In-First-Out): First element added is first to be removed

Apply with purpose

In Apply mode, test one operation and explain its complexity before running the next.

Predict next

Before clicking run, predict the next index/pointer movement and then verify it.