Queue Class 12: NCERT Computer Science Chapter 4 PDF

This is Chapter 4, Queue, of the NCERT Class 12 Computer Science textbook (subject code 083, edition published for the 2025-26 session). The chapter runs across printed pages 53–66, and the official PDF is right below — the same file NCERT publishes, free, with nothing added or removed.

Everything else on this page is a guided reading of the chapter: where each idea lives, how the FIFO and deque concepts work, and which exercise practises which skill, all keyed to the same page numbers so you can follow along in your own book.

Download the official NCERT chapter PDF

Download the official NCERT Class 12 Computer Science Chapter 4 Queue PDF — it is the exact file NCERT publishes on its own server, so no other copy is needed and nothing is missing or rearranged. The PDF holds all fourteen printed pages of the chapter, from the “In this Chapter” list on page 53 to the closing exercise on page 66.

The link opens in your browser and can be saved or printed for offline revision. If you want the complete book instead of a single chapter, the Related Resources section at the end points to NCERT’s textbook portal, where every Class 12 Computer Science chapter PDF is published.


What the chapter holds Count Where it is used
Printed pages 14
Sections in the chapter 9
Figures with NCERT captions 5
Tables 1
Exercise questions 8 answered in our NCERT Solutions
Activities 4
Official NCERT PDF Download the chapter PDF the chapter exactly as NCERT publishes it

Chapter 4 Queue at a glance

This section orients you before you read: it names the chapter’s five parts as the book lists them, and places the chapter in the sequence of the book. The counts table on this page shows how much of each kind the chapter holds — its sections, figures, activities and exercises; what follows is what it teaches.

The “In this Chapter” list on page 53 names five parts:

  • Introduction to Queue
  • Operations on Queue
  • Implementation of Queue using Python
  • Introduction to Deque
  • Implementation of Deque using Python

The chapter is built on a contrast with Chapter 3: the Stack worked Last-In-First-Out (LIFO), and the Queue works its opposite, First-In-First-Out (FIFO) (NCERT, p. 53). As you read, you will also meet four Activities and two “Think and Reflect” prompts, which ask you to reason beyond the printed code.

What this chapter covers, section by section

This guided tour follows the five parts the book lists up front, so you know where each idea lives and how the pieces connect. Each part opens with the single idea you need before the details.

Queue: the FIFO idea (pages 53–55)

Before any code, fix one picture: a queue is a line. People join at the back and leave from the front, and the person who has waited longest leaves first — that is the whole chapter in one sentence.

A queue is an ordered linear list of elements with different ends for adding and removing elements (NCERT, p. 53). It follows FIFO — First In, First Out — also called First Come First Served (FCFS): the element that entered first leaves first, so the element longest in the queue is removed first (p. 54).

The end where elements are added is the Rear (also the Tail); the end from which elements are removed is the Front (also the Head) (p. 54).

Real-life queues the chapter gives (p. 54):

  • Train waiting list — a W/L1 ticket is at the front of the waiting queue and gets confirmed first when a confirmed ticket is cancelled.
  • IVRS customer service — calls wait in a queue until a support person is free.
  • Single-lane one-way road — the vehicle that entered first exits first.
  • Toll booth — vehicles are served on a FIFO basis.

Computer science uses the same structure (p. 55):

  • Web server — a server that can handle a maximum of 50 concurrent result-viewing requests queues thousands of user requests and serves them in order.
  • Operating system job scheduling — jobs wait in a queue for the processor and are given access on a FIFO basis.
  • Shared printer — print commands from different files are queued and sent to the printer one by one.

Operations on a queue (pages 55–56)

A queue is useful only if you can add to it, remove from it and check its state. These five operations, introduced on page 55, are the chapter’s vocabulary.

Operation What it does What can go wrong
ENQUEUE Insert a new element at the rear end Overflow if inserted beyond capacity
DEQUEUE Remove one element at a time from the front Underflow if removed from an empty queue
isEmpty Check whether the queue has any element Avoids underflow during dequeue
peek View the front element without removing it —
isFull Check whether more elements can be added Avoids overflow during enqueue

One implementation note from the chapter: when a list is used for a queue, either end of the list can be fixed as the Front, as long as the opposite end is fixed as the Rear (p. 55–56).

The chapter’s trace table (Figure 4.3, p. 56) writes the queue’s state in the form F → element ← R, with the Front on the left and the Rear on the right — this arrow format is exactly what the exercise questions ask for.

Implementing a queue in Python (pages 56–59)

This is where the FIFO idea becomes functions. Python lists already do most of the work — the chapter defines five small functions around the list and explains why a sixth is unnecessary.

  • Create the queue: myQueue = list().
  • enqueue uses append(), which always adds at the end of the list — the rear (p. 56).
  • dequeue uses pop(0), which removes the element at index 0 — the front (p. 57).
  • isEmpty checks len(myQueue) == 0; size returns len(myQueue) (p. 56–57).
  • peek reads myQueue[0]; if the queue is empty it prints ‘Queue is empty’ and returns None (p. 57).
  • No isFull needed — Python lists are dynamic, so a list-based queue never runs out of space. Overflow belongs to fixed-size implementations (p. 56).

The five functions together (pp. 56–57):

myQueue = list()
def enqueue(myQueue, element):
    myQueue.append(element)  # adds at the rear
def isEmpty(myQueue):
    return len(myQueue) == 0
def dequeue(myQueue):
    if not isEmpty(myQueue):
        return myQueue.pop(0)  # removes from the front
    else:
        print(“Queue is empty”)
def peek(myQueue):
    if isEmpty(myQueue):
        print(‘Queue is empty’); return None
    return myQueue[0]
def size(myQueue):
    return len(myQueue) The chapter then runs a bank counter scenario (p. 58): people coded P1, P2, … join the queue, a person is served, the queue size is printed, three more people join, and finally a while not isEmpty(myQueue) loop removes everyone.

In the printed output the last message, “Queue is empty”, is the dequeue guard doing its job — the loop tried to remove one more person and the function reported that no one was left (p. 59).

Deque: a double-ended queue (pages 59–61)

A deque (pronounced “deck”) is a queue with the restriction removed: elements can be added or removed at either end (p. 59). Because no side is restricted, the same structure can implement a stack or a queue.

The four operations (p. 60):

  • InsertFront — insert a new element at the front of the deque.
  • InsertRear — same as a normal queue, insert at the rear.
  • DeletionFront — same as a normal queue, remove from the front.
  • DeletionRear — remove one element at a time from the rear.

Applications the chapter lists (pp. 59–60): browser history (the most recently closed URL opens first, and when the stored list grows too large the least-visited URLs are removed from the end), undo/redo in a text editor, and checking whether a string is a palindrome.

The palindrome method is written out as Algorithm 4.1 (p. 61): insert the string’s characters one by one at the rear as in a normal queue, then remove one character from each end and compare the pair, repeating until the deque is empty or holds a single character.

Activities 4.3 and 4.4 (p. 60) ask the key question of this section: when insertion and deletion happen at the same end, the deque behaves as a stack; when they happen at opposite ends, it behaves as a queue.

Implementing a deque in Python (pages 61–64)

The deque implementation reuses the queue’s functions and adds two list methods for the second end.

  • insertFront uses insert(0, element) — the start of the list is the front (p. 62).
  • insertRear uses append(element) — identical to enqueue (p. 62).
  • deletionFront uses pop(0) — identical to dequeue (p. 62).
  • deletionRear uses pop() with no index — that removes the last element, the rear (p. 62).
  • getFront returns myDeque[0]; getRear returns myDeque[len(myDeque) – 1] (p. 62).

The four end-operations in code (pp. 62–63):

def insertFront(myDeque, element):
    myDeque.insert(0, element)  # index 0 = front
def insertRear(myDeque, element):
    myDeque.append(element)  # end of list = rear
def deletionFront(myDeque):
    if not isEmpty(myDeque):
        return myDeque.pop(0)  # removes the front
def deletionRear(myDeque):
    if not isEmpty(myDeque):
        return myDeque.pop()  # no index = rear Program 4-2’s main() asks the user to choose mode 1 (normal queue) or mode 2 (stack-like behaviour), then shows how the same deque functions serve both purposes (p. 63).

In both printed outputs the run ends with “Queue underflow” and then None — again the empty-guard printing a message, not a program error (p. 64).

The chapter deliberately sets Stack and Queue side by side: Chapter 3’s stack was LIFO, inserting and deleting at the same end; this chapter’s queue is FIFO, inserting at one end and deleting at the other. Whenever you write an answer about a queue, check which two ends you used — one job per end is the whole design.

Key concepts: FIFO, front and rear, and tracing a queue

This section is the mental model behind every exercise. The FIFO rule decides where every element goes and when it leaves; the trace technique is the skill the exercises test.

Memory aid for the ends: in the arrow form F → … ← R, the Rear is where you join the line (elements enter) and the Front is where you leave (elements exit) — the element at the Front is First In, First Out. In a Python list, the Front is always index 0.

Trace a queue after every operation

The chapter’s trace format (Figure 4.3, p. 56) shows the state after every operation: F → marks the front, ← R marks the rear, and the elements between them sit in order from front to rear. Here is the same trace on a fresh set of values — enqueue 10, enqueue 20, dequeue, enqueue 30, peek, then three dequeues:

Operation Status of the queue after the operation
enqueue(10) F → 10 ← R
enqueue(20) F → 10 | 20 ← R
dequeue() F → 20 ← R
enqueue(30) F → 20 | 30 ← R
peek() F → 20 | 30 ← R (peek returns 20; queue unchanged)
dequeue() F → 30 ← R
dequeue() F → (empty) ← R
dequeue() Underflow — ‘Queue is empty’ printed, nothing removed

Watch what Front did: after every dequeue it moved one place right. The element at F is always the one that has waited longest, and that is FIFO in action. The last dequeue is the underflow case — dequeuing an empty queue triggers the guard, not a crash.

These are fresh values, not the exercise’s own numbers (Q6 uses 34, 54, 12, 61), so practise the same arrow format with the exercise’s values too.

Run a deque as a queue, then as a stack

Deque operations look abstract until you trace them. The two traces below use the same kind of letter-based deque and show why same-end usage gives a stack while opposite-end usage gives a queue (Activities 4.3 and 4.4, p. 60). Status is shown from front (left) to rear (right).

Queue mode — insert at the rear, delete from the front (opposite ends):

Operation Deque status
insertRear(‘A’) A
insertRear(‘B’) A | B
insertRear(‘C’) A | B | C
deletionFront() B | C (A removed)
insertRear(‘D’) B | C | D
deletionFront() C | D (B removed)
deletionFront() D (C removed)
deletionFront() empty (D removed)

Removal order A, B, C, D is the insertion order — FIFO, exactly a queue.

Stack mode — insert and delete at the same end (the rear):

Operation Deque status
insertRear(‘X’) X
insertRear(‘Y’) X | Y
insertRear(‘Z’) X | Y | Z
deletionRear() X | Y (Z removed)
insertRear(‘W’) X | Y | W
deletionRear() X | Y (W removed)
deletionRear() X (Y removed)
deletionRear() empty (X removed)

Removal order Z, W, Y, X is reverse insertion order — LIFO, exactly a stack.

Queue vs stack vs deque, side by side

Two comparisons do the work of this chapter. First, queue against stack (the previous chapter’s structure):

Feature Queue Stack
Principle FIFO — first in, first out (p. 53) LIFO — last in, first out (p. 53)
Insertion end Rear (Tail) Same end as deletion — the top (p. 60)
Deletion end Front (Head) Same as insertion — the top (p. 60)
Python insert method append() — adds at the rear append() — adds at the same end
Python delete method pop(0) — removes the front pop() — removes the same end, no index
Typical use Job queues, printer queues, web-server requests (p. 55) Browser history, undo/redo — most recent first (p. 60)

Then queue against deque:

Feature Queue Deque
Ends used Two, each with a fixed job Both ends fully open
Insertion Only at the rear At the rear or the front
Deletion Only from the front From the front or the rear
Acts as a stack No Yes — same-end insert and delete (p. 60)
Acts as a queue Yes — by definition Yes — opposite-end insert and delete (p. 60)

Figure walkthrough: queues and deques in pictures


This section reads each diagram in the chapter with you, so the pictures teach the idea rather than just decorate the page. One clarification first: Figure 4.3 (p. 56) is not a photograph — it is the status table of queue states that the Key concepts section above uses, in the arrow format F → … ← R.

The first diagram (p. 53) is a queue of people at a bank.

A queue of people standing in line at a bank counter, with the person at the front served first, showing the FIFO principle
Figure 4.1 Queue of people at a bank. Source: NCERT

The person at the front, who arrived first, is served first; everyone behind moves up one place. This is FIFO in real life, and it is exactly the behaviour the enqueue and dequeue functions reproduce on a list.

Figure 4.2 (p. 54) shows the same idea in traffic.

A row of cars waiting in line at a petrol pump, the vehicle that entered first exiting first, illustrating a queue in real life
Figure 4.2 Queue of cars in a petrol pump. Source: NCERT

A queue of cars at a petrol pump: the car that entered the line first exits first. Nothing can cut in from the middle — elements leave only from the front, which is the rule a program must enforce.

Figure 4.4 (p. 59) is the basic deque structure displaying head and tail.

A deque drawn as a row with both ends open and labelled head and tail, showing that elements can be added or removed from either end
Figure 4.4 Basic deque structure displaying head and tail to implement stack or queue. Source: NCERT

Compare it with a normal queue: both ends are open, so insertion and deletion are allowed at either end. This single difference is why a deque can be a stack or a queue — you choose the ends you operate on.

Figures 4.5 and 4.6 (p. 61) belong to Algorithm 4.1, the palindrome check on the word ‘madam’.

A deque holding the first four letters of the word madam, head on the left and tail on the right, midway through the palindrome algorithm
Figure 4.5 Status of Deque after 4th iteration. Source: NCERT

By the 4th iteration of the loop, four characters have been inserted from the rear, one per iteration — m, a, d, a — with the head at the left and the tail at the right. The fifth character, m, is still to come.

The deque after one character has been removed from each end, with the removed pair to be compared, continuing the palindrome check
Figure 4.6 Status of Deque after removing one character from both the ends. Source: NCERT

This is the compare-and-remove step: one character leaves each end, and the algorithm compares the removed pair. If they match, it repeats — removing another pair — until the deque is empty or holds one character. Every pair matching means ‘madam’ is a palindrome; the first mismatch ends the check.

Definitions: the terms to know for Chapter 4

This table is a quick-revision glossary of every new term in the chapter, with the page where each appears. Keep the definitions short — scan them the night before, not the morning of.

Term Meaning in this chapter NCERT page
Queue Ordered linear list of elements with different ends for adding and removing p. 53
FIFO / First Come First Served The element entered first leaves first; the element longest in the queue is removed first p. 54
Front / Head The queue’s removal end p. 54
Rear / Tail The queue’s addition end p. 54
Enqueue Insert a new element at the rear p. 55
Dequeue Remove one element from the front p. 55
Overflow Exception when enqueue goes beyond capacity p. 55
Underflow Exception when dequeue is attempted on an empty queue p. 55
isEmpty Checks whether the queue has any element p. 55
isFull Checks whether more elements can be added p. 55–56
Peek Views the front element without removing it p. 56
Deque (double-ended queue) Structure in which insertion and deletion can happen at either end p. 59
InsertFront / InsertRear / DeletionFront / DeletionRear Insert at the front, insert at the rear, delete from the front, delete from the rear p. 60
getFront / getRear Read the front or rear element without removing it p. 62

Four Python list methods carry these ideas in code:

Python method Job in this chapter NCERT page
append(element) enqueue / insertRear — adds at the end, the rear p. 56
pop(0) dequeue / deletionFront — removes index 0, the front p. 57
pop() deletionRear — no index, so it removes the last element, the rear p. 62
insert(0, element) insertFront — adds at index 0, the front p. 62

Common mistakes students make with queues

These eight errors are ones the chapter’s own functions, Activities and printed output reveal. Each is a small decision — which end, which method, which guard — easy to fix once named.

Mistake Correct rule How to check your answer
1. Swapping the ends Enqueue inserts at the rear; dequeue removes from the front. A queue never removes from the rear (p. 54–55) Read your dequeue: does it use pop(0)?
2. Using pop() for a queue’s dequeue pop() removes the rear element; a queue must remove the front, so the index 0 is essential (p. 57) Your dequeue must contain pop(0)
3. Confusing deletionRear with deletionFront deletionRear uses pop() with no index; deletionFront uses pop(0) — each removes a different end (p. 62) The rear deletion has no index; the front deletion has 0
4. Dequeuing an empty queue The guarded functions print ‘Queue is empty’ or ‘Queue underflow’ and return None; always guard with isEmpty first (p. 57, 63) Is your dequeue wrapped in an if not isEmpty check?
5. Writing isFull for a Python list queue Python lists are dynamic; a list-based queue never overflows — overflow belongs to fixed-size implementations (p. 56) Your Python implementation needs no isFull
6. Mixing up when a deque is a stack vs a queue Same end for insertion and deletion → stack; opposite ends → queue (Activities 4.3, 4.4, p. 60) Trace one insert and one delete — which ends did they use?
7. Misreading the palindrome loop Remove one character from each end and compare the pair; continue only while the deque has more than one character (Algorithm 4.1, p. 61) Does your loop stop when one character is left?
8. Reading the final ‘Queue is empty’ as an error In the printed output, the last message is the underflow guard working — a normal end, not a crash (p. 59, 64) The message comes from the guarded else branch

Answers to the two Think and Reflect prompts

Think and Reflect (p. 55) — urgent administrator request: a plain FIFO queue would make the administrator wait behind every student request already in line. A fair strategy is priority handling: enqueue the urgent request at the front, or keep a separate high-priority queue that is serviced before the normal queue.

The prompt’s point is that FIFO is fair but not urgency-aware.

Think and Reflect (p. 57) — can a queue be built on a tuple or dictionary? A tuple cannot: it is immutable, so adding or removing elements is impossible without rebuilding a new tuple each time.

A dictionary is not a natural fit either: it stores values by key, not by position, so it has no built-in “first element” or “append at the end” to match a queue’s ordered ends. A mutable, position-ordered Python list is exactly why the chapter uses it.

How this chapter is asked: exam practice

This section maps the exercise at the end of the chapter to the skill each question tests, so you practise the right thing. One honest warning first: no one can promise which questions will appear, and textbook contents and the examinable syllabus are not always identical — check the current official syllabus before planning your revision.

Question Tests this skill Concept taught on
Q1 Definitions and vocabulary: queue, FIFO order, enqueue/dequeue, the front end, the deletion sequence of A–S–D–F, deque, and a mixed-end deletion order for a deque p. 53–60
Q2 Compare queue with stack — LIFO against FIFO p. 53
Q3 Explain FIFO — the element longest in the queue leaves first p. 54
Q4 Write a menu-driven program using a queue (shuttlecocks in a box) — enqueue, dequeue, isEmpty p. 56–59
Q5 Compare queue with deque — one open end against two p. 59–60
Q6 Trace the status of a queue after each operation, in the arrow format of Figure 4.3 p. 55–56
Q7 Trace the status of a deque after each operation, mixing front and rear p. 60–63
Q8 Palindrome check using a deque — Algorithm 4.1 is the given hint p. 61

For Q1, every blank is a term in the Definitions table above.

Two blanks deserve a second look: (e) with A, S, D, F in the queue, the sequence received is A, S, D, F — the same order they entered, because deletion is always from the front; and (g) with z, x, c, v, b in the deque, the deletion order z, b, v, x, c is produced by deletionFront, deletionRear, deletionRear, deletionFront, deletionRear — a mix of both ends, which is exactly what makes a deque different from a queue.

The four Activities and what each asks

The chapter embeds four Activities (p. 58 and p. 60); each is a small self-check on the code just read:

  • Activity 4.1 (p. 58) — avoid printing None for an empty queue: check with isEmpty before printing, because peek returns None when the queue has no element.
  • Activity 4.2 (p. 58) — list the complete queue: write a function that traverses the list from index 0 to the last element. (The menu-loop and traversal patterns in the sorting notes for Class 12 Computer Science are a useful companion when writing this kind of function.)
  • Activity 4.3 (p. 60) — insertion and deletion from the same end makes the deque behave as a stack (option 2).
  • Activity 4.4 (p. 60) — insertion and deletion from opposite ends makes it behave as a queue (option 1).

Practical tip: be ready to write the six deque helper functions from memory — insertFront, insertRear, deletionFront, deletionRear, getFront, getRear — plus isEmpty. That combination is the chapter’s complete toolset for Q8 and for any programming question built on a deque.

Revision summary: the chapter in ten points

This is the chapter’s own SUMMARY (p. 64) rebuilt for quick revision — ten points in the order the book presents them. If you remember only three things: FIFO — the longest-waited element leaves first; enter at the rear, leave at the front; and a deque works at both ends, so it can be a stack or a queue.

  • A queue is an ordered linear data structure that serves elements in the order they arrived — the FIFO strategy.
  • Front marks the end where removal happens; Rear marks the end where addition happens.
  • In Python, the predefined list methods manage Front and Rear automatically.
  • Insertion in a queue happens at the rear end.
  • Deletion happens at the front end.
  • Insertion is called enqueue; deletion is called dequeue.
  • isEmpty, isFull and peek are the supporting operations for the main two.
  • A deque is a version of the queue that allows insertion and deletion at both ends.
  • Because both ends are open, a deque can support both stack and queue operations.
  • The complete deque vocabulary: insertfront, insertrear, deletefront, deleterear, getfront, getrear, isempty and isfull.

Continue from this chapter in any of these directions:

  • Class 12 Computer Science NCERT book page — every chapter of this book, including its PDFs.
  • Chapter 3: Stack — the LIFO data structure this chapter is built against.
  • Class 12 hub — all Class 12 NCERT book pages on this site.
  • CBSE notes for Class 12 Computer Science — revision material for the full subject.
  • Class 12 notes home and the main CBSE notes page for every class.
  • Students who also take Informatics Practices can compare the treatment in the Class 12 IP chapter notes.
  • Every chapter PDF in the book comes from the official NCERT textbook portal — the single authoritative source for Class 12 Computer Science.

Sources and data verification

This page describes the NCERT Class 12 Computer Science textbook (subject code 083), Chapter 4, ‘Queue’, printed pages 53–66, in the official edition published on ncert.nic.in.

It covers only this chapter of the Class 12 Computer Science NCERT book — not other computer science textbooks, and not the full CBSE subject scheme.

This listing is maintained for the academic session 2026-27 using the NCERT edition currently published on ncert.nic.in.

NCERT settles textbook editions, chapters and official PDFs; CBSE settles the curriculum and the examinable syllabus. Textbook contents and the examinable syllabus are not always identical, so check the current official CBSE syllabus before planning your revision.

Reference: NCERT Class 12 Computer Science textbook, chapter 4, official edition on ncert.nic.in.

Frequently asked questions about Queue (Class 12)

What is a queue in class 12 Computer Science?

A queue is an ordered linear list of elements in which addition and removal happen at different ends: new elements enter at the rear and existing elements leave from the front (NCERT, p. 53–54). It follows FIFO (First In, First Out), so the element that has been in the queue longest is removed first.

What is the difference between enqueue and dequeue in a queue?

Enqueue inserts a new element at the rear of the queue, while dequeue removes one element at a time from the front (NCERT, p. 55). In Python these are implemented with append() for enqueue and pop(0) for dequeue.

What is the difference between queue and deque?

A queue allows insertion only at one end (the rear) and deletion only at the other (the front). A deque (double-ended queue, pronounced “deck”) allows insertion and deletion at both ends, so the same structure can behave as a stack or as a queue (NCERT, p. 59).

How do you implement a queue using a list in Python?

Create an empty list with myQueue = list(); enqueue with append() (adds at the rear), dequeue with pop(0) (removes from the front), and check emptiness or size with len(); peek reads myQueue[0] (NCERT, p. 56–57). No isFull function is needed because Python lists are dynamic and a list-based queue never overflows.

How do you check whether a string is a palindrome using a deque?

Insert each character of the string at the rear, like a normal queue. Then repeatedly remove one character from the front and one from the rear and compare the pair; if every pair matches until the deque is empty or holds a single character, the string is a palindrome (Algorithm 4.1, NCERT, p. 61).

Explore Class 12 Computer Science Books

Related chapters:


Related

More from this section