Class 12 Computer Science Chapter 4 Question Bank CBSE Board Pattern

Section A — MCQs (1 mark each)

  1. Which principle does a Queue data structure follow?
    (a) LIFO (b) FIFO (c) FILO (d) LILO

  2. In a Queue, new elements are always added at the ______ end.
    (a) Front (b) Rear (c) Middle (d) Both ends

  3. Which operation is used to view the element at the front of the queue without removing it?
    (a) enqueue (b) dequeue (c) peek (d) isFull

  4. Trying to perform dequeue on an empty queue results in:
    (a) Overflow (b) Underflow (c) IndexError (d) None

  5. In Python list implementation of queue, which statement correctly removes an element from the front?
    (a) myQueue.pop() (b) myQueue.pop(0) (c) myQueue.append(0) (d) myQueue.insert(0)

Assertion-Reason Questions

  1. Assertion (A): Queue is also known as First Come First Served (FCFS) approach.
    Reason (R): The element that enters the queue first is the first one to be removed.
    (a) Both A and R are true and R is the correct explanation of A.
    (b) Both A and R are true but R is not the correct explanation of A.
    (c) A is true but R is false. (d) A is false but R is true.

  2. Assertion (A): Python does not require an isFull() function while implementing queue using list.
    Reason (R): Python lists are dynamic and can grow as needed.
    (a) Both A and R are true and R is the correct explanation of A.
    (b) Both A and R are true but R is not the correct explanation of A.
    (c) A is true but R is false. (d) A is false but R is true.

  3. In a deque, insertion and deletion of elements from the same end makes it behave like a:
    (a) Queue (b) Stack (c) List (d) None of these

  4. Which of the following is not a valid operation on a deque?
    (a) insertFront (b) deletionRear (c) insertMiddle (d) getRear

  5. The function used to check whether a queue contains any element is:
    (a) size() (b) isEmpty() (c) peek() (d) enqueue()

Section B — Very Short Answer (2 marks each)

  1. Define Queue. State the principle it follows.
  2. Differentiate between Stack and Queue on the basis of principle of operation and ends used for insertion/deletion.
  3. What is the difference between enqueue and dequeue operations?
  4. What will be the output of the following code fragment?
    python myQueue = [] enqueue(myQueue, 'A') enqueue(myQueue, 'B') print(dequeue(myQueue)) print(size(myQueue))
  5. What is a Deque? How is it different from a normal Queue?
  6. Write the output of the following operations on a deque (initially empty):
    insertFront(10), insertRear(20), deletionFront(), getRear()

Section C — Short Answer (3 marks each)

  1. Explain the role of isEmpty() and peek() functions while performing dequeue operation on a queue. Why are they required?
  2. The following code is written to implement enqueue operation. Identify the error and write the corrected code.
    python def enqueue(myQueue, element): myQueue.insert(0, element)
  3. Show the status of the queue after each of the following operations (start with empty queue):
    enqueue(5), enqueue(12), dequeue(), enqueue(7), peek(), size()
  4. Write a short Python code fragment to display all elements of a queue without deleting them.
  5. What happens when we perform deletionRear() on a deque? How is it different from deletionFront()?

Section D — Long Answer (5 marks each)

  1. Write a complete Python program to implement a queue of students waiting for result declaration using list. The program should allow enqueue, dequeue, display size and peek operations through a menu.
  2. Explain the algorithm to check whether a given string is a palindrome using deque. Dry-run the algorithm on the string “level” using a trace table showing status of deque after each step.
  3. Write user-defined functions insertFront(), insertRear(), deletionFront() and isEmpty() to implement a deque using Python list. Also write the main() function to demonstrate all four operations.

Section E — Case/Source-Based (4 marks each)

Case 1: A bank has introduced a digital token system where customers take tokens and wait in a queue to be served at the cash counter. The system must handle arrival of new customers, serving the person at the front, displaying the number of people waiting and checking if the counter is free.

(a) Which data structure is most suitable and why?
(b) Which operation will be performed when a new customer arrives?
(c) Which operation will be performed when the cashier calls the next customer?
(d) Which supporting function should be used before calling the next customer to avoid underflow?

Case 2: A browser maintains history of visited URLs using a deque so that both recently closed and least visited URLs can be managed.

(a) Which two operations of deque will be used to add a new URL and remove the least visited URL?
(b) How can the same deque be used to implement the “Undo” feature in a text editor?
(c) Write the function call to read the most recently visited URL without removing it.
(d) What will happen if deletion is attempted when the deque is empty?

Answer Key Attempt all questions first,
then tap to reveal

Section A

  1. (b) FIFO
  2. (b) Rear
  3. (c) peek
  4. (b) Underflow
  5. (b) myQueue.pop(0)
  6. (a)
  7. (a)
  8. (b) Stack
  9. (c) insertMiddle
  10. (b) isEmpty()

Section B

  1. Queue is an ordered linear list of elements in which insertion takes place at rear and deletion at front following FIFO principle.
  2. Stack: LIFO, same end for insertion & deletion. Queue: FIFO, different ends for insertion & deletion.
  3. enqueue inserts at rear; dequeue removes from front.
  4. Output:
    A
    1
    (Reason: First element inserted is removed by dequeue; one element remains.)
  5. Deque allows insertion and deletion from both ends; normal queue restricts insertion to rear and deletion to front.
  6. After operations: Front = 20, Rear = 20 (only 20 remains)

Section C

  1. isEmpty() prevents underflow before dequeue; peek() allows viewing front element without removal.
  2. Error: insert(0,…) adds at front instead of rear. Correct code uses append().
  3. Trace: [5] → [5,12] → [12] → [12,7] → 12 (peek) → 2 (size)
  4. Use a loop with peek() or iterate while preserving elements.
  5. deletionRear() removes last element; deletionFront() removes first element.

Section D

  1. Complete menu-driven program using enqueue, dequeue, size, peek and isEmpty (as per NCERT implementation).
  2. Palindrome algorithm trace table for “level” showing deque status after each insertRear and paired deletion.
  3. Four functions with proper list operations + demonstration in main().

Section E

Case 1: (a) Queue (FIFO) (b) enqueue (c) dequeue (d) isEmpty()
Case 2: (a) insertRear & deletionRear (b) insertRear & deletionRear for recent/least visited (c) getRear() (d) Underflow message

All questions are answerable from the NCERT chapter text. Reviewed by GFIS faculty.