2nd pu notes

Computer Science Chapter 4 – Queue – Complete Notes, Q&A & Exam Preparation

Venkatesh A August 26, 2026 13 min read
2nd PUC / Class 12 Computer Science

Complete Short Notes & Exam Preparation Guide

Based on the NCERT textbook PDF. The notes below keep the chapter sequence, technical terms, Python implementation, algorithms, figures and exam-oriented ideas from the selected chapter, while simplifying the prose for revision.

SubjectComputer Science
Class2nd PUC / Class XII
Chapter4
NameQueue
verakworld.com

πŸ“š Table of Contents

  1. 4.1 Introduction to Queue
    1. 4.1.1 First In First Out (FIFO)
    2. 4.1.2 Applications of Queue
  2. 4.2 Operations on Queue
  3. 4.3 Implementation of Queue using Python
  4. 4.4 Introduction to Deque
    1. 4.4.1 Applications of Deque
    2. 4.4.2 Operations on Deque
  5. 4.5 Implementation of Deque Using Python
  6. Textbook Exercise
  7. Summary
  8. Questions & Answers
  9. Important Questions
  10. ⚑ Quick Revision
  11. Final Revision
verakworld.com

4.1 Introduction to Queue

A queue is an ordered linear list of elements in which the ends used for adding and removing elements are different. A queue follows First-In-First-Out (FIFO), unlike the stack’s LIFO approach.

Examples shown in the chapter include students waiting in a line, customers at a bank cash counter and vehicles waiting at a fuel pump.

⭐ Exam Point: In a queue, insertion and deletion happen at different ends.
CashierNextQueue of people waiting at a bank cash counter
Figure 4.1: Queue of people at a bank
verakworld.com

4.1.1 First In First Out (FIFO)

In FIFO, the element that enters the queue first is the first one to leave. The element that has stayed in the queue the longest is removed first. FIFO is also known as the First Come First Served (FCFS) approach.

  • REAR = end where new items are added.
  • FRONT = end from which items are removed.
  • REAR is also called TAIL.
  • FRONT is also called HEAD.
New item
β†’
REAR / TAIL
β†’
FRONT / HEAD
β†’
Item removed
Petrol PumpVehicles queued at a petrol pump
Figure 4.2: Queue of cars in a petrol pump
verakworld.com

4.1.2 Applications of Queue

(A) Real-life applications

  • Train-ticket waiting lists: waiting numbers form a queue and the ticket at the front can be confirmed when a confirmed ticket is cancelled.
  • Customer-service / IVRS calls: callers wait in a queue until support is available.
  • Single-lane roads and toll booths: vehicles are served according to the queue order.

(B) Computer-science applications

  • Web-server requests: a queue can hold large numbers of requests when only a limited number can be handled concurrently.
  • Operating-system jobs: jobs waiting for processor access can be queued and served in an order such as FIFO.
  • Print requests: the OS queues requests sent to a shared printer and sends them one by one on a FIFO basis.
Chapter thinking prompt: The web-server example asks how requests with different urgency might be handled. The chapter presents this as a question rather than giving an extended strategy in the selected text.

4.2 Operations on Queue

OperationPurposeExam point
ENQUEUEInsert a new element at the rear.Insertion beyond capacity gives Overflow.
DEQUEUERemove one element from the front.Deletion from an empty queue gives Underflow.
IS EMPTYChecks whether the queue has any element.Used to avoid Underflow during dequeue.
PEEKViews the front element without deleting it.Reads the current front item.
IS FULLChecks whether more elements can be added.Helps avoid Overflow in a fixed-capacity queue.
Queue operation stagesOperationStatus of queueenqueue(z)enqueue(x)enqueue(c)dequeue()enqueue(v)dequeue()dequeue()ZZXZXCXCXCVCVVF→←RF→←RF→←RF→←RF→←RF→←RF→←R
Figure 4.3: Various stages of queue operations
verakworld.com

4.3 Implementation of Queue using Python

The chapter implements a queue using Python’s list data type. A list does not have a fixed size in the manner described for a fixed-capacity queue, so the chapter does not implement IS FULL for this list-based version.

When a list is used, one end is designated Front and the other end Rear. The implementation shown uses the list end for Rear and index 0 for Front.

Create queue

myQueue = list()

enqueue()

def enqueue(myQueue, element):
    myQueue.append(element)

append() adds the element at the end of the list, which is the Rear.

isEmpty()

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

dequeue()

def dequeue(myQueue):
    if not (isEmpty(myQueue)):
        return myQueue.pop(0)
    else :
        print("Queue is empty")

pop(0) removes the first item, so it represents deletion at the Front.

size()

def size(myQueue):
    return len(myQueue)

peek()

def peek(myQueue):
    if isEmpty(myQueue):
        print('Queue is empty')
        return None
    else:
        return myQueue[0]

Bank cash-counter scenario – Program 4-1

myQueue = list()
# each person to be assigned a code as P1, P2, P3,...
element = input("enter person’s code to enter in queue :")
enqueue(myQueue,element)
element = input("enter person’s code for insertion in queue :")
enqueue(myQueue,element)
print("person removed from queue is:", dequeue(myQueue))
print("Number of people in the queue is :",size(myQueue))
element = input("enter person’s code to enter in queue :")
enqueue(myQueue,element)
element = input("enter person’s code to enter in queue :")
enqueue(myQueue,element)
element = input("enter person’s code to enter in queue :")
enqueue(myQueue,element)
print("Now we are going to remove remaining people from the queue")
while not isEmpty(myQueue):
    print("person removed from queue is ",
    dequeue(myQueue))

Output

enter person’s code to enter in queue :P1
enter person’s code to enter in queue :P2
person removed from the queue is :p1
number of people in the queue is :1
enter person’s code to enter in queue :P3
enter person’s code to enter in queue :P4
enter person’s code to enter in queue :P5
Now we are going to remove remaining people from the queue
person removed from the queue is :p2
person removed from the queue is :p3
person removed from the queue is :p4
person removed from the queue is :p5
Queue is empty
verakworld.com
Activity 4.1: Think about how to avoid printing None when trying to print an empty queue.
Activity 4.2: Think about how to list the complete contents of the queue by writing a suitable function.

4.4 Introduction to Deque

Deque (pronounced β€œdeck”) permits insertion and removal from either end: head/front or tail/rear. Because both ends can be used, it can implement stack or queue behaviour. It is also called a Double ended queue.

(insertion) Push →← Push (insertion)(deletion) Pop →← Pop (deletion)FrontRear
Figure 4.4: Basic deque structure displaying head and tail to implement stack or queue
verakworld.com

4.4.1 Applications of Deque

Real-life contexts

  • Train-ticket counter: a person who already purchased a ticket may return later and be allowed to join from the front.
  • Highway toll booth: vehicles may move from one queue toward a vacant booth, involving removal and joining from an end.

Computer-science contexts

  • Browser history: the chapter describes stack-like history behaviour and removal of older/least-visited URLs when storage is limited.
  • Do and Undo in a text editor.
  • Palindrome checking by deleting and matching characters from both ends.

4.4.2 Operations on Deque

OperationMeaning
INSERTFRONTInsert at the front.
INSERTREARInsert at the rear, like a normal queue.
DELETIONFRONTRemove from the front.
DELETIONREARRemove from the rear.

The deque also needs supporting operations used with a normal queue, including Is Empty, Peek and Size.

Activity idea from the chapter: if insertion and deletion are performed at the same end, deque behaves like a stack; if they are at opposite ends, it behaves like a queue.

Algorithm 4.1 – Palindrome checking using deque

  1. Traverse the string madam from the left, one character at a time.
  2. Insert each character into the deque with INSERTREAR.
  3. Repeat the first two steps for all characters.
  4. Remove one character from the Front and one from the Rear using DELETIONFRONT and DELETIONREAR.
  5. Match the two removed characters.
  6. If they match, repeat until the deque is empty or has one character left; otherwise stop because the string is not a palindrome.
Figure 4.5 – Status of Deque after 4th iterationmadaFrontRear← insertrear(m)
Figure 4.5: Status of Deque after 4th iteration
verakworld.com
Figure 4.6 – Removing one character from both endsadaremovefront(m) →← insertrear(m)FrontRear
Figure 4.6: Status of Deque after removing one character from both the ends
verakworld.com

4.5 Implementation of Deque Using Python

Like the queue, the deque is implemented with the Python list data type in this chapter.

myDeque = list()

insertFront()

def insertFront(myDeque, element):
    myDeque.insert(0,element)

insertRear()

def insertRear(myDeque,element):
    myDeque.append(element)

isEmpty()

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

deletionRear()

def deletionRear(myDeque):
    if not (isEmpty()):
        return myDeque.pop()
    else :
        print("Deque empty")

getFront()

def getFront(mydeque):
    if not (isEmpty()):
        return mydeque[0]
    else :
        print(" Queue empty")

getRear()

def getRear(mydeque):
    if not (isempty()):
        return mydeque[len(mydeque)-1]
    else :
        print(" Deque empty")

Deletion from Front: its implementation is the same as the queue’s dequeue() because the first element is removed with pop(0).

return myDeque.pop(0)

Program 4-2 – Implementation of Deque in Python

def insertFront(myDeque,element):
    myDeque.insert(0,element)
def getFront(myDeque):
    if not (isEmpty(myDeque)):
        return myDeque[0]
    else:
        print("Queue underflow")
def getRear(myDeque):
    if not (isEmpty(myDeque)):
        return myDeque[len(myDeque)-1]
    else:
        print ("Queue underflow")
def insertRear(myDeque,element):
    myDeque.append(element)
def isEmpty(myDeque):
    if len(myDeque) == 0:
        return True
    else:
        return False
def deletionRear(myDeque):
    if not isEmpty(myDeque):
        return myDeque.pop()
    else:
        print("Queue underflow")
def deletionFront(myDeque):
    if isEmpty(myDeque):
        print("Queue underflow")
    else:
        return myDeque.pop(0)
def main():
    dQu = list()
    choice = int(input('enter 1 to use as normal queue 2 otherwise : '))
    if choice == 1:
        element = input("data for insertion at rear ")
        insertRear(dQu,element)
        element = getFront(dQu)
        print("data at the beginning of queue is ", element)
        element = input("data for insertion at front ")
        insertRear(dQu,element)
        print('data removed from front of queue is ', deletionFront(dQu))
        print('data removed from front of queue is ', deletionFront(dQu))

Output

enter 1 to use as normal queue 2 otherwise : 1
data for insertion at rear 23
data at the beginning of queue is 23
data for insertion at rear 45
data removed from front of queue is 23
data removed from front of queue is 45
Queue underflow
data removed from front of queue is None
enter 1 to use as normal queue 2 otherwise : 2
data for insertion at front 34
data at the end of queue is 34
data for insertion at front 56
data removed from rear of queue is 34
data removed from rear of queue is 56
Queue underflow
data removed from rear of queue is None
verakworld.com

πŸ“˜ Textbook Exercise – Chapter Practice

Exercise topics from the chapter

  1. Complete the chapter fill-in-the-blank concepts: queue definition, FIFO order, enqueue/dequeue, deletion end, the order of received elements, deque definition and the deletion sequence in a deque.
  2. Compare and contrast a queue with a stack.
  3. Explain how FIFO describes a queue.
  4. Write a menu-driven Python program using a queue to implement movement of a shuttlecock in its box.
  5. Explain how a queue data type differs from a deque data type.
  6. Show the status of a queue after the given sequence of enqueue, dequeue and peek operations.
  7. Show the status of a deque after the given sequence of peek, insertFront, insertRear, deletionFront and deletionRear operations.
  8. Write a Python program to check whether a given string is a palindrome using a deque, referring to Algorithm 4.1.
verakworld.com
Activity 4.3: Determine the behaviour when insertion and deletion in a deque are performed at the same end; the chapter uses this to test recognition of stack behaviour.
Activity 4.4: Determine the behaviour when insertion and deletion in a deque are performed at opposite ends; the chapter uses this to test recognition of queue behaviour.

Chapter Summary

Queue

  • Ordered linear data structure.
  • Follows FIFO.
  • Front and Rear mark the two ends.
  • Insertion at Rear; deletion at Front.
  • Python list implementation uses predefined list methods for the two ends.

Deque

  • Double-ended queue.
  • Insertion and deletion at either end.
  • Can support stack and queue behaviour.
  • Important operations include insertfront, insertrear, delete/deletion front and rear, getfront, getrear and isempty.
verakworld.com

❓ Questions & Answers

1-Mark: Define queue.

A queue is an ordered linear list in which insertion and deletion take place at different ends, following FIFO.

1-Mark: What is FIFO?

First In First Out: the element that enters first is removed first.

1-Mark: What is Overflow?

It is the exception produced when an element is inserted beyond queue capacity.

1-Mark: What is Underflow?

It is the exception produced when deletion is attempted from an empty queue.

1-Mark: What is deque?

A double-ended queue allowing insertion and deletion at either end.

2-Mark: Explain enqueue and dequeue.

Enqueue inserts at Rear. Dequeue removes from Front.

2-Mark: What do isEmpty and peek do?

isEmpty checks whether the queue has elements. peek reads the Front item without deleting it.

2-Mark: Name deque operations.

INSERTFRONT, INSERTREAR, DELETIONFRONT and DELETIONREAR.

3-Mark: Explain FIFO with Front and Rear.

Items enter at Rear/Tail and leave from Front/Head. The earliest entered item leaves first.

3-Mark: Give computer-science applications of queue.

The chapter describes web-server requests, OS jobs waiting for processor access and shared-printer requests.

3-Mark: Explain palindrome checking with deque.

Insert characters from the Rear and compare characters removed from Front and Rear until the deque becomes empty or has one character, stopping on a mismatch.

4/5-Mark: Explain queue implementation in Python.

Use a list, then define enqueue, isEmpty, dequeue, size and peek as shown in the chapter.

4/5-Mark: Explain Algorithm 4.1.

Traverse the string, INSERTREAR each character, then remove from both ends and compare until the stopping condition is reached.

4/5-Mark: Explain deque implementation in Python.

Use a list and define insertion, deletion, isEmpty, getFront and getRear functions, followed by the program’s main routine.

πŸ“ Important Questions

1 Mark

  1. Define queue.
  2. Expand FIFO and FCFS.
  3. Which end is used for insertion in a queue?
  4. Which end is used for deletion?
  5. What is Overflow?
  6. What is Underflow?
  7. Define deque.

2 Marks

  1. Differentiate enqueue and dequeue.
  2. Explain isEmpty and peek.
  3. State the roles of Front and Rear.
  4. Write the basic list methods used in the chapter for queue and deque.

3 Marks

  1. Explain FIFO.
  2. Explain queue applications given in the chapter.
  3. Explain the four basic deque operations.
  4. Explain palindrome checking using deque.

4/5 Marks

  1. Write the Python functions for implementing a queue using a list.
  2. Write the bank queue program and explain its output.
  3. Explain Algorithm 4.1 with the figures.
  4. Write the Python deque program and explain its output.
  5. Compare queue and deque with respect to insertion and deletion.
These are chapter-derived practice questions. They are not claimed to be officially repeated board questions.

⚑ Quick Revision

Important Definitions

  • Queue: ordered linear list; insertion/deletion at different ends; FIFO.
  • FIFO: First In First Out.
  • Deque: double-ended queue.
  • Overflow: insertion beyond capacity.
  • Underflow: deletion from an empty queue.

Important Terms

REARTAILFRONTHEADENQUEUEDEQUEUEPEEKIS EMPTYIS FULLINSERTFRONTINSERTREARDELETIONFRONTDELETIONREARgetFrontgetRear

Important Differences

BasisQueueDeque
InsertionRearFront or Rear
DeletionFrontFront or Rear
BehaviourFIFOCan act as queue or stack

Important Syntax

myQueue = list()
myQueue.append(element)
myQueue.pop(0)
myDeque.insert(0,element)
myDeque.append(element)
myDeque.pop()
myDeque[len(myDeque)-1]

Important Programs

  • Queue implementation using list.
  • Bank cash-counter queue scenario.
  • Deque implementation in Python.
  • Palindrome checking using deque.

Important Figures

  • Figure 4.1 – bank queue
  • Figure 4.2 – petrol-pump queue
  • Figure 4.3 – queue operation stages
  • Figure 4.4 – basic deque structure
  • Figure 4.5 – deque after 4th iteration
  • Figure 4.6 – deque after removal from both ends
verakworld.com

Final Revision

Queue = FIFO: insert at Rear, delete at Front.
Deque = both ends: insert and delete at Front or Rear.
Python queue: list + append() + pop(0), with the support functions shown in the chapter.
Palindrome: insert from Rear, compare removals from both ends.
Exam focus: definitions, operations, Front/Rear, Python functions, deque operations, Algorithm 4.1, programs and figures.
verakworld.com

VerakWorld – 2nd PUC / Class 12 Computer Science

Chapter 4: Queue – Complete Short Notes & Exam Preparation Guide

Source basis: NCERT textbook PDF for this chapter.

verakworld.com

Leave a Comment