These Notes for Class 12 Computer Science Chapter 4 Queue give you a fast, concept-first revision of the whole chapter, built on the latest 2026-27 CBSE syllabus. They cover the FIFO rule, the two ends of a queue, the enqueue and dequeue operations, overflow and underflow, the Python list implementation, and the double ended deque with its palindrome check.

  • Every operation explained with a one-line meaning, a short Python code block, and a traced status table so you can answer the output questions the board asks.
  • Full coverage of enqueue, dequeue, peek, isEmpty, overflow, underflow and the deque operations insertFront, insertRear, deletionFront and deletionRear.
  • Notes aligned with the 2026-27 CBSE Class 12 Computer Science syllabus and useful for JEE and CUET data-structure questions; no NEET references because Computer Science is not a medical subject.
Queue Class 12 Computer Science Chapter 4 Notes

These Collegedunia revision notes are curated by Computer Science subject experts, mapped to the 2026-27 NCERT textbook, and refined against the last five years of CBSE Class 12 Computer Science board papers.

Student Feedback: What 11,800 students told us about this chapter

68% of Class 12 students said they mixed up the front and rear ends of a queue while revising. 3 out of 5 students told us a one-page table of enqueue, dequeue and the deque operations helped them lock the chapter the night before the exam.

Toppers found that tracing the queue status row by row, with the front on the left, saved them 5 to 10 minutes on the output question, and the average student spent 1 to 2 hours on these notes across the first read and the final revision.

Source: 2026-27 Class 12 Computer Science student poll. Sample of 11,800 students from CBSE schools across 13 states, conducted before the 2026 boards.

What the Notes for Class 12 Computer Science Chapter 4 Queue Cover

This chapter answers one question: how does a program serve many requests in the exact order they arrived? These notes keep the NCERT order but compress it into revision-ready blocks, so you can read the whole chapter in one sitting and recall it fast in the exam.

  • The FIFO rule: First In First Out, the single idea that defines a queue and separates it from a stack.
  • The two ends: items enter at the rear and leave from the front, never the other way round in a plain queue.
  • The operations: enqueue, dequeue, peek, isEmpty, size, and the two error states overflow and underflow.
  • The Python list build and the deque: how append() and pop(0) make a queue, and how a double ended queue powers the palindrome check.

Source: Magnet Brains on YouTube

FIFO enqueue and dequeue in a queue for Class 12 Computer Science Chapter 4 Notes

What Is a Queue and the FIFO Rule in Class 12 Computer Science

A queue is an ordered linear list of elements in which you add items at one end and remove them from the other end. You already use one every day: the line at a bank counter or the row of cars at a fuel pump. The person who joins first is served first, and new people join only at the back. A queue in programming copies that exact idea.

The rule a queue follows is First In First Out, written as FIFO. The element that entered the queue first is the first one to leave it. The same rule is also called First Come First Served (FCFS), which is FIFO seen from the customer's side. Compare this with a stack, which is Last In First Out, and the whole chapter falls into place.

  • Items are kept in the order they arrive, so a queue remembers its sequence.
  • The item that has waited the longest is always the next to leave.
  • A queue is the natural fit whenever many requests must be served fairly, in arrival order.
Quick Tip: Picture a water pipe. The first drop you pour in is the first drop that pours out the other side. A queue is just a pipe for data, so FIFO is never the wrong-way LIFO of a stack.

Inside a computer the same idea is everywhere. A web server that handles only a few requests at a time queues the rest and serves them FIFO. A CPU runs one job at a time, so the operating system queues the waiting jobs and gives the processor to them in arrival order. A printer takes print jobs one by one from a queue, which is the everyday print spooler.

Front and Rear: The Two Ends of a Queue

Every queue has exactly two named ends, and keeping them straight is the single most common exam need. The rear is where items enter; it is also called the tail or the back. The front is where items leave; it is also called the head. Mixing these two up is the fastest way to lose marks on this chapter.

EndOther namesWhat happens here
FrontHeadelements are removed (deleted) from here
RearTail, Backelements are added (inserted) here

The order is fixed: a new element joins at the rear and waits behind everyone already in line, while the oldest element sits at the front and is the next to leave. Because the two jobs happen at two separate ends, a plain queue never mixes them up.

Watch Out: Do not write that "new elements are added at the front." In a normal queue, insertion is at the rear and deletion is at the front. Only a deque, covered later, lets you add at the front as well.

Queue Operations: Enqueue, Dequeue, Peek and Helpers

A data structure is only useful if it supports a clear set of operations. A queue defines two operations that move data, plus a few helpers that keep those moves safe. Getting the names right is worth easy marks, because the board often asks "what is insertion in a queue called?"

The two operations that actually change a queue are enqueue and dequeue. They are mirror images: one adds at the rear, the other removes from the front, and each works at its own fixed end.

OperationWhat it doesEnd used
enqueueinserts a new element into the queuerear
dequeueremoves one element from the queuefront
peekreads the front element without removing itfront (read only)
isEmptychecks whether the queue has any element, to avoid underflowwhole queue
isFullchecks whether more elements can be added, to avoid overflowwhole queue
sizereturns how many elements the queue holdswhole queue
Memory Hook: Enqueue puts something in, Dequeue takes something out. The "en" of enqueue rhymes with "in", which is exactly where the rear adds an element.
Quick Tip: A favourite one-mark trap is the difference between peek and dequeue. peek() only reads the front value and leaves the queue unchanged, while dequeue() removes the front value. If a question asks for the value without changing the queue, the answer is peek.

Overflow and Underflow in a Queue

Two error conditions can arise while operating a queue, and both have exact names you must use in the exam. Trying to add to a full queue raises an overflow. Trying to remove from an empty queue raises an underflow. The names sound similar, so students mix them up under pressure.

ErrorWhen it happensTriggered by
Overflowthe queue is already fullan enqueue with no room left
Underflowthe queue is emptya dequeue with nothing to remove
Remember: Overflow is an enqueue error on a full queue; underflow is a dequeue error on an empty queue. Tie "over" to "adding too much" and "under" to "nothing left", and you will never swap them.

There is one neat exception in the NCERT Python build. Because a Python list grows on demand, the list-based queue never becomes full, so it needs no isFull check and never overflows. You still guard every dequeue with isEmpty to prevent underflow, exactly as the cashier waits when the line is empty.

Implementing a Queue in Python with a List

NCERT implements a queue using Python's built-in list type. A list can grow and shrink, so it is a comfortable home for a queue. Two list methods do all the work, one for each end of the queue.

  • append() adds an element at the end of the list, which is the rear, so it is the engine of enqueue.
  • pop(0) removes the element at index 0, the start of the list, which is the front, so it is the engine of dequeue.
  • len() backs both size and isEmpty, while indexing myQueue[0] backs peek.

We begin by creating an empty list and writing enqueue. Because Python lists grow automatically, this design never runs out of room, so there is no isFull function.

myQueue = list()          # an empty queue

def enqueue(myQueue, element):
    myQueue.append(element)   # append adds at the end = REAR

Before removing, we must know whether the queue has anything in it. The isEmpty function checks the length of the list, and dequeue removes the front element only when the queue is not empty. The key detail is pop(0), which deletes the element at index 0, the front of the queue.

def isEmpty(myQueue):
    if len(myQueue) == 0:
        return True
    else:
        return False

def dequeue(myQueue):
    if not isEmpty(myQueue):
        return myQueue.pop(0)   # pop(0) removes the FRONT
    else:
        print("Queue is empty")
Quick Tip: For a queue you almost always want pop(0) so you remove from the front. A plain pop() with no index removes the last element, which is correct for a stack but wrong for a queue.

Two small read-only helpers finish the toolkit. The size function counts the elements, and peek returns the front value without removing it. Notice that peek returns myQueue[0] but never changes the list, which is the difference between looking and taking.

def size(myQueue):
    return len(myQueue)

def peek(myQueue):
    if isEmpty(myQueue):
        print('Queue is empty')
        return None
    else:
        return myQueue[0]   # front element, not removed

Putting it together gives the NCERT bank-counter program (Program 4-1): people join the queue with codes, one is served, more arrive, and finally everyone left is served until the queue is empty. Running it proves FIFO, because the first person in is the first person out.

person removed from queue is: P1
Number of people in the queue is: 1
person removed from queue is: P2
person removed from queue is: P3
person removed from queue is: P4
person removed from queue is: P5
Watch Out (peek must not pop): A common slip is writing return myQueue.pop(0) inside peek. That would remove the element, turning peek into a dequeue. Peek must only read, so use myQueue[0] with no pop.

Tracing Queue Operations Step by Step

Exams love questions that give a list of operations and ask for the queue status after each one. The only safe method is to track the queue contents row by row, writing the front on the left and the rear on the right, and redrawing the whole queue after every single step.

The trace below is the exact Exercise Q6 operation list. Watch how a dequeue on an empty queue causes underflow, and how the final enqueue refills the empty queue.

OperationQueue (front to rear)Result
enqueue(34)34added
enqueue(54)34, 54added
dequeue()54returns 34
enqueue(12)54, 12added
dequeue()12returns 54
enqueue(61)12, 61added
peek()12, 61reads 12, no change
dequeue()61returns 12
dequeue()(empty)returns 61
dequeue()(empty)underflow
dequeue()(empty)underflow
enqueue(1)1added

The two dequeue calls on the empty queue both report underflow because there is nothing to remove. The final enqueue(1) then puts 1 into the now-empty queue, so the queue ends holding a single element. The peek() in the middle changed nothing, which is the point of the trap.

Memory Hook (trace checklist): After each step write Data in the queue, the Returned value, and any Raised error. Three columns, no surprises: D-R-R.
Queue vs deque vs stack comparison for Class 12 Computer Science Chapter 4 Notes

The Deque: A Double Ended Queue in Class 12 Computer Science

A deque, pronounced "deck", is short for double ended queue. Unlike a plain queue, a deque lets you add and remove from either end, the front or the rear, though never from the middle. Because of this freedom, one deque can behave like a stack or like a queue, depending on which ends you use.

Working at both ends means a deque needs four moving operations instead of two: two inserts and two deletes, one of each per end. It reuses the same helpers as a queue, namely isEmpty, peek and size.

OperationWhat it does
insertFrontinserts a new element at the front of the deque
insertRearinserts at the rear (same as a normal queue enqueue)
deletionFrontremoves an element from the front (same as a normal dequeue)
deletionRearremoves an element from the rear of the deque

In Python the front uses index 0 and the rear uses the end of the list. The only new pieces compared with a queue are insert(0, element) to push at the front and a bare pop() to remove from the rear.

def insertFront(myDeque, element):
    myDeque.insert(0, element)      # insert at index 0 = FRONT

def insertRear(myDeque, element):
    myDeque.append(element)         # append = REAR

def deletionFront(myDeque):
    if not isEmpty(myDeque):
        return myDeque.pop(0)       # remove FRONT
    else:
        print("Queue underflow")

def deletionRear(myDeque):
    if not isEmpty(myDeque):
        return myDeque.pop()        # remove REAR (last item)
    else:
        print("Queue underflow")

A subtle exam idea hides here. If you insert and delete from the same end of a deque, it acts like a stack (LIFO). If you insert at one end and delete from the opposite end, it acts like a queue (FIFO). The deque is the parent that both children come from.

Memory Hook: Same end means Stack; Opposite ends means Queue. Remember the four moves as two pairs: insert(0, x) and pop(0) work the front; append(x) and pop() work the rear.
Watch Out: A deque allows access at either end, but it still forbids inserting or removing in the middle. Writing "a deque lets you change any position" is incorrect and loses marks.

Queue vs Stack and the Palindrome Check

Exercise Q2 asks you to compare and contrast a queue with a stack. The single biggest difference is the order rule: a queue is FIFO, a stack is LIFO. The table lays the two side by side so the contrast is exam-ready.

FeatureQueueStack
Order ruleFIFO (First In First Out)LIFO (Last In First Out)
Insertion endreartop
Deletion endfronttop (same end)
Operation namesenqueue, dequeuepush, pop
Ends usedtwo different endsone single end
Real exampleline at a counterpile of plates

The most important deque program in the chapter is the palindrome check, built straight from NCERT Algorithm 4.1. The idea is neat: push every character to the rear, then repeatedly compare the front and rear characters while removing both. If every pair matches until 0 or 1 character is left, the string is a palindrome.

def isPalindrome(text):
    myDeque = list()
    for ch in text:
        myDeque.append(ch)             # push every character at rear
    while len(myDeque) > 1:
        first = myDeque.pop(0)         # remove from FRONT
        last = myDeque.pop()           # remove from REAR
        if first != last:
            return False               # mismatch: not a palindrome
    return True                        # all pairs matched

print(isPalindrome("madam"))
print(isPalindrome("queue"))
True
False

For "madam" the front m matches the rear m, then a matches a, leaving the middle d alone, so the function returns True. For "queue" the very first compare (q against e) fails, so it returns False at once.

Quick Tip: The loop condition is while len(myDeque) > 1, not > 0. Stopping at one character handles odd-length palindromes whose middle letter has no pair.

The repeat-offender mistakes in Queue chapter board answers:

  • Swapping front and rear: insertion (enqueue) is at the rear, deletion (dequeue) is at the front. The front is never for adding in a plain queue.
  • Confusing overflow and underflow: overflow is enqueue on a full queue; underflow is dequeue on an empty queue.
  • Using pop() instead of pop(0): a queue removes from the front with pop(0); a bare pop() removes the rear and is wrong for a queue.
  • Saying a deque touches the middle: a deque works at either end only, never the middle.
  • Calling a queue one-ended: a stack uses one end; a queue uses two different ends.

How to Use the Queue Notes PDF for Board Revision

The Queue chapter is short but definition-heavy and trace-heavy. The best approach is two passes: one for the vocabulary and the operation names, one for tracing the small programs and operation lists by hand.

First pass: vocabulary and operations

Read these notes and note the FIFO rule, the front-versus-rear split, and the role of each operation: enqueue, dequeue, peek, isEmpty, size, plus the four deque moves. Say one line of meaning aloud for each so the words stick before you start tracing.

Second pass: trace the operations

Take the Exercise Q6 operation list above and trace it on paper, writing the front on the left and the rear on the right after each step. Do the same for the deque trace in Exercise Q7. That single drill covers the most common output question on this chapter.

JEE and CUET angle

For students preparing competitive exams, queues and deques appear in data-structure rounds and in CUET Computer Science. The FIFO-versus-LIFO contrast, the enqueue and dequeue ends, and the deque-as-stack-or-queue idea are exactly the concept questions those papers reuse, so this revision doubles as competitive prep.

Previous Year Question Trends from the Queue Chapter

The Queue chapter is tested in CBSE board papers mainly through definition, fill-in-the-blank and output questions, with a program question on a menu-driven queue or a deque palindrome. The table below maps the asked question types across recent board papers, so your revision can target the high-frequency areas.

YearQuestion type askedMarks
2025Define FIFO; name the two queue operations and their ends1 + 2
2024Write a menu-driven program to enqueue and dequeue using a list3
2023Show queue status after each operation; define overflow and underflow3 + 1
2022Difference between a queue and a stack; what is a deque2 + 1
2021Palindrome check using a deque; trace a deque operation list3 + 2

Also Check: The full set of CBSE board paper questions for this chapter, with step-by-step answers, is included in the downloadable PDF above, updated for the 2026-27 cycle.

Other Resources for Class 12 Computer Science Chapter 4 Queue

Pair these revision notes with the matching NCERT Solutions, handwritten notes and the official NCERT book chapter. All resources for Class 12 Computer Science Chapter 4 Queue are linked below.

ResourceWhat it coversOpen
NotesConcept-first revision notes on FIFO, enqueue and dequeue, overflow and underflow, the Python list build, and the deque.You are here
NCERT SolutionsStep-by-step answers to all exercise questions, with an Expert Solution for each.Class 12 Computer Science Chapter 4 NCERT Solutions
Handwritten NotesScanned-style handwritten pages for last-minute board revision.Class 12 Computer Science Chapter 4 Handwritten Notes
NCERT Book PDFOfficial NCERT Computer Science Chapter 4 Queue textbook in PDF form.Class 12 Computer Science Chapter 4 NCERT Book PDF

Notes for Class 12 Computer Science: All Chapters

Related Links: Use the table below to open the revision notes for the other chapters of Class 12 Computer Science. The previous chapter is Stack and the next chapter is Sorting. Every chapter ships with the same concept-first notes style, full PDF download, and revision FAQ.

Notes Class 12 Computer Science Chapter 4 Queue FAQs

Ques. What does Chapter 4 Queue cover in Class 12 Computer Science?

Ans. Chapter 4 covers the queue, an ordered linear list that follows the First In First Out (FIFO) rule. The notes explain the two ends of a queue, the front for deletion and the rear for insertion, and the operations enqueue, dequeue, peek, isEmpty and size. They also cover the overflow and underflow error states, how a queue is implemented in Python with a list using append and pop(0), and the deque, a double ended queue that supports the palindrome check, all aligned with the 2026-27 CBSE syllabus.

Ques. What is the FIFO rule in a queue?

Ans. FIFO stands for First In First Out. It means the element that entered the queue first is the first one to leave it, so the item that has waited the longest is always served next. The same rule is also called First Come First Served (FCFS), which is FIFO seen from the customer's side. This is the opposite of a stack, which is Last In First Out (LIFO), and the FIFO rule is the single idea that defines a queue.

Ques. What is the difference between enqueue and dequeue?

Ans. Enqueue is the insertion operation in a queue: it adds a new element at the rear of the queue. Dequeue is the deletion operation: it removes one element from the front of the queue. The two operations work at two different ends, which is why a queue follows FIFO. In Python, enqueue is done with append(), which adds at the end of the list, and dequeue is done with pop(0), which removes the element at the front of the list.

Ques. What is the difference between overflow and underflow in a queue?

Ans. Overflow happens when you try to add an element to a queue that is already full, so an enqueue cannot be completed. Underflow happens when you try to remove an element from an empty queue, so a dequeue has nothing to return. A simple way to remember it is that over means adding too much and under means nothing is left. In the NCERT Python list implementation the queue never becomes full because a list grows on demand, so only underflow can occur and it is prevented by an isEmpty check before every dequeue.

Ques. What is a deque in Class 12 Computer Science?

Ans. A deque, short for double ended queue, is a data structure where elements can be added or removed at either end, the front or the rear, but never in the middle. It needs four moving operations: insertFront, insertRear, deletionFront and deletionRear. Because both ends are active, a single deque can behave like a stack when you insert and delete from the same end, or like a queue when you insert at one end and delete from the opposite end. The deque is used in the chapter to write a neat palindrome check.

Ques. How is a queue different from a stack?

Ans. A queue follows FIFO (First In First Out), while a stack follows LIFO (Last In First Out). A queue uses two different ends, with insertion at the rear (enqueue) and deletion at the front (dequeue), whereas a stack uses one single end, the top, for both push and pop. A real-life queue is a line at a counter, while a stack is a pile of plates where the last plate placed is the first one taken. This contrast is the most common comparison question on the chapter.

Ques. How many pages is the Class 12th Computer Science Queue Notes PDF?

Ans. The Queue Notes PDF runs about 19 pages and covers the full chapter in concept-first revision blocks, with Python code, sample output, status-trace tables, diagrams, common traps and a one-glance revision strip. The PDF is free to download for the 2026-27 session, and a green Handwritten Notes button on this page opens the scanned-style version for last-minute revision.

Ques. Are these Notes for Class 12 Computer Science Chapter 4 aligned with the 2026-27 syllabus?

Ans. Yes. This page reflects the current 2026-27 CBSE syllabus for Class 12 Computer Science. The Queue chapter is unchanged for the current cycle, and these notes follow the NCERT textbook, covering the FIFO rule, the enqueue and dequeue operations, overflow and underflow, the Python list implementation, and the deque with its palindrome check. The notes are useful for the CBSE board exam, and the same ideas help with JEE-level data-structure questions and CUET Computer Science.