Kundali IQ

Home › Free notes › Class 12 Computer Science › Queue

Queue – Class 12 Computer Science notes, important questions and MCQs

NCERT Class 12 Computer Science, chapter 4. Notes, key terms, important questions with answers and MCQs.

हिंदी में पढ़ें

Chapter overview

A queue is a linear data structure in which elements are inserted at one end, called the rear, and removed from the other end, called the front. It follows the First In First Out (FIFO) principle, like people standing in a line. The main operations are ENQUEUE and DEQUEUE. Queues are implemented in Python using lists, and a deque (double-ended queue) allows insertion and deletion at both ends.

Queue and its operations

  • In a queue, the element inserted first is removed first (FIFO).
  • ENQUEUE adds an element at the rear; DEQUEUE removes an element from the front; PEEK returns the front element without removing it; isEmpty checks whether the queue is empty; overflow and underflow occur as in stacks.
  • In Python, a list is used: queue.append(x) for ENQUEUE and queue.pop(0) for DEQUEUE; queue[0] gives the front element.

Applications and deque

  • Applications include printer job queues, CPU scheduling, ticket booking, call centre waiting lines and handling requests on a web server.
  • A deque (double-ended queue) allows insertion and deletion at both front and rear; it can work as both a stack and a queue.
  • Deque operations in a Python list: insertFront with insert(0, x), insertRear with append(x), deletionFront with pop(0), deletionRear with pop(); a deque can be used to check palindromes by comparing elements removed from both ends.

Key terms

Queue
a linear data structure following FIFO
FIFO
First In First Out
ENQUEUE
inserting an element at the rear of a queue
DEQUEUE
removing an element from the front of a queue
Deque
a double-ended queue allowing operations at both ends

Important questions with answers

Distinguish between a stack and a queue.2 marks

A stack follows LIFO; insertion and deletion happen at one end called the top (PUSH and POP). A queue follows FIFO; insertion happens at the rear (ENQUEUE) and deletion at the front (DEQUEUE). Stacks are used for undo, queues for scheduling.

Write Python functions for ENQUEUE and DEQUEUE operations.3 marks

def enqueue(q, x): q.append(x). def dequeue(q): if len(q) == 0: print('Queue is empty'); return None, else: return q.pop(0). The end of the list is the rear and index 0 is the front.

Explain queues and deques with their operations and applications.5 marks

A queue is a linear data structure that follows the First In First Out (FIFO) principle: the element that is inserted first is removed first, just as the first person in a line is served first. Elements are added at one end called the rear and removed from the other end called the front. The main operations are ENQUEUE, which inserts an element at the rear; DEQUEUE, which removes and returns the element at the front; PEEK, which shows the front element without removing it; isEmpty, which checks whether the queue has no elements; and size, which returns the number of elements. Trying to dequeue from an empty queue is underflow. In Python, a list can implement a queue using append(x) for ENQUEUE and pop(0) for DEQUEUE. Queues are used in printer spooling, CPU and process scheduling, handling requests on servers, call centres, ticket counters and breadth-first search. A deque, or double-ended queue, is a more flexible structure in which elements can be inserted and deleted at both ends. Its operations are insertFront, insertRear, deletionFront and deletionRear, implemented in a list with insert(0, x), append(x), pop(0) and pop(). A deque can act as a stack if insertion and deletion happen at the same end, and as a queue if they happen at opposite ends. Applications include checking palindromes, undo-redo with limited history and maintaining browser history.

Quick revision

  • FIFO principle.
  • ENQUEUE, DEQUEUE, PEEK, isEmpty.
  • Implementation using lists.
  • Applications; deque and its operations.

Exam tips

  • Queue in a Python list: append() to enqueue, pop(0) to dequeue.
  • Compare stack (LIFO, one end) with queue (FIFO, two ends).

Practice MCQs

  1. A queue follows the principle

    1. LIFO
    2. random order
    3. FIFO
    4. priority only
    Show answer

    Answer: (c) FIFO. First In First Out.

  2. Adding an element to a queue is called

    1. PUSH
    2. ENQUEUE
    3. DEQUEUE
    4. POP
    Show answer

    Answer: (b) ENQUEUE. It happens at the rear.

  3. Elements are removed from a queue at the

    1. rear
    2. middle
    3. front
    4. top
    Show answer

    Answer: (c) front. The oldest element leaves first.

  4. For a Python list used as a queue, DEQUEUE is done by

    1. pop()
    2. append()
    3. pop(0)
    4. insert(0, x)
    Show answer

    Answer: (c) pop(0). The front is index 0.

  5. A data structure allowing insertion and deletion at both ends is a

    1. deque
    2. stack
    3. simple queue
    4. tuple
    Show answer

    Answer: (a) deque. Double-ended queue.

  6. Which situation is best modelled by a queue

    1. undo in an editor
    2. printing documents in the order they were sent
    3. evaluating postfix
    4. browser back button
    Show answer

    Answer: (b) printing documents in the order they were sent. Jobs are served in order.

  7. If 10, 20, 30 are enqueued in order and one DEQUEUE is done, the front element becomes

    1. 10
    2. none
    3. 30
    4. 20
    Show answer

    Answer: (d) 20. 10 is removed first.

  8. Why can a deque be used to check whether a string is a palindrome

    1. it sorts characters
    2. characters can be removed from both ends and compared
    3. it stores only vowels
    4. it reverses words automatically
    Show answer

    Answer: (b) characters can be removed from both ends and compared. Matching front and rear characters confirms a palindrome.

All chapters of Class 12 Computer Science

Written by Kundali IQ from standard, well-established facts to help with revision. This is not an official NCERT publication; always read your textbook too.