Computer ScienceClass 12Queue

Queue in Class 12 Computer Science: Concepts and Operations Explained

By ConceptScroll Team · Published on 17 July 2026 · 5 min read

Queue in Class 12 Computer Science: Concepts and Operations Explained

In Class 12 Computer Science, the Queue is a fundamental data structure based on the FIFO principle. It allows insertion at the rear and deletion at the front, making it essential for tasks like scheduling and buffering.

What is a Queue in Computer Science?

A Queue is a linear data structure that stores elements in a specific order. It follows the FIFO (First In First Out) principle, meaning the element inserted first is the one to be removed first.

In a queue, insertion happens at the rear end, and deletion happens at the front end. This structure is similar to a real-life queue, like a line at a ticket counter, where the first person to join the line is the first to be served.

Queues are widely used in computer science for managing tasks such as scheduling processes, handling requests in web servers, and buffering data streams.

Key points:

  • Linear list with insertion and deletion at different ends
  • Maintains order of elements based on arrival
  • Used in various applications like CPU scheduling, printer spooling, etc.

Basic Operations on Queue: Enqueue and Dequeue

The two fundamental operations on a queue are:

  • Enqueue: Adds an element at the rear of the queue.
  • Dequeue: Removes an element from the front of the queue.

Other supporting operations include:

  • Is Empty: Checks if the queue has no elements to avoid underflow.
  • Is Full: Checks if the queue is at maximum capacity to avoid overflow.
  • Peek: Views the front element without removing it.

How Operations Work

OperationDescription
Enqueue(z)Insert 'z' at rear
Enqueue(x)Insert 'x' after 'z'
Enqueue(c)Insert 'c' after 'x'
Dequeue()Remove 'z' from front
Enqueue(v)Insert 'v' at rear
Dequeue()Remove 'x' from front
Dequeue()Remove 'c' from front

This sequence shows how the queue evolves with each operation, maintaining the FIFO order.

Want to test yourself on Queue? Try our free quiz →

Understanding Overflow and Underflow in Queues

Two important exceptions to remember when working with queues are Overflow and Underflow:

  • Overflow: Occurs when you try to enqueue an element but the queue is already full. No more elements can be added.
  • Underflow: Happens when you try to dequeue an element from an empty queue. There are no elements to remove.

To prevent these exceptions, always check:

  • If the queue is full before enqueueing.
  • If the queue is empty before dequeueing.

This ensures smooth operation without runtime errors.

Example:

Suppose a queue has a maximum size of 3.

  • Enqueue A → Queue: A
  • Enqueue B → Queue: A, B
  • Enqueue C → Queue: A, B, C
  • Enqueue D → Overflow error (queue full)
  • Dequeue → Removes A, Queue: B, C
  • Dequeue → Removes B, Queue: C
  • Dequeue → Removes C, Queue empty
  • Dequeue → Underflow error (queue empty)

Queue vs Stack: A Quick Comparison

Though both Queue and Stack are linear data structures, they differ significantly in how elements are added and removed.

FeatureQueueStack
OrderFIFO (First In First Out)LIFO (Last In First Out)
InsertionAt rear endAt top
DeletionFrom front endFrom top
Example Use CasesScheduling, bufferingRecursion, expression evaluation
AccessSequential from front to rearOnly top element accessible

Understanding these differences helps in choosing the right data structure for specific problems.

Real-Life Applications of Queue in Computer Science

Queues are fundamental in many computer science applications, especially where order and fairness matter.

Common applications include:

  • CPU Scheduling: Processes are scheduled in the order they arrive.
  • Printer Queue: Print jobs are handled one by one in arrival order.
  • Web Server Request Handling: Requests are served in the order received.
  • Breadth-First Search (BFS): Uses queue to explore nodes level-wise.
  • Data Buffering: Queues buffer data streams to manage speed differences.

Activity to Reflect

Consider a web server that needs to prioritize urgent requests (like an administrator’s) while still serving others fairly. How can the queue be modified or combined with other data structures to handle this?

This introduces concepts like priority queues, which extend the basic queue structure.

Implementing Queue Operations: A Simple Example

Let’s look at a simple example of queue operations to understand the concept better.

Suppose we start with an empty queue and perform these operations:

1. Enqueue(A) 2. Enqueue(B) 3. Enqueue(C) 4. Dequeue() 5. Enqueue(D)

Step-by-step:

StepQueue Status
StartEmpty
Enqueue(A)A
Enqueue(B)A, B
Enqueue(C)A, B, C
Dequeue()B, C
Enqueue(D)B, C, D

Result: The first element 'A' is removed first, confirming the FIFO principle.

This example helps Class 12 students visualize how enqueue and dequeue work practically.

Frequently asked questions

What does FIFO mean in the context of a queue?

FIFO means First In First Out, where the first element added is the first to be removed.

What is the difference between enqueue and dequeue operations?

Enqueue adds an element at the rear, while dequeue removes an element from the front.

How does a queue differ from a stack?

Queue follows FIFO with insertion at rear and deletion at front; stack follows LIFO with both at top.

What causes overflow and underflow in a queue?

Overflow happens when enqueue is done on a full queue; underflow occurs when dequeue is done on an empty queue.

Can elements be inserted or deleted from the middle of a queue?

No, insertion and deletion happen only at the rear and front ends respectively in a queue.

Why are queues important in computer science?

Queues manage tasks in order, useful in scheduling, buffering, and handling requests fairly.

Ready to ace this chapter?

Get the full Queue chapter — interactive notes, diagrams, worked solutions, polls and a free practice quiz — in the ConceptScroll app.

Open in ConceptScroll →

Study smarter with ConceptScroll

Daily NCERT-aligned reels, AI doubt solving and chapter quizzes — all free.

Start learning free
#class 12#computer science#data structure#dequeue#enqueue#fifo#ncert#queue

Continue reading