Worksheets › Class 12 › Queue

Class 12 · Computer Science worksheet

Queue

CBSE Computer Science. FIFO, enqueue and dequeue on a list, front and rear, underflow, the deque and checking palindromes, choosing a stack, queue or deque. Every sheet has 20 questions in three sections and an answer key, and the questions change every time.

Open a printable sample sheet

Sample questions

Real questions from this chapter, as the app sets them. Tap Answer to see the answer and working.

Section A · multiple choice

  1. 1.

    A queue works on the principle of:

    1. largest first
    2. random order
    3. Last In, First Out (LIFO)
    4. First In, First Out (FIFO)
    Answer

    (d) First In, First Out (FIFO)

  2. 2.

    What is the last line this program prints? def enqueue(q, x):     q.append(x) def dequeue(q):     if len(q) == 0:         return 'Underflow'     return q.pop(0) q = [] enqueue(q, 86) enqueue(q, 89) enqueue(q, 81) print(dequeue(q)) enqueue(q, 63) print(dequeue(q)) enqueue(q, 83) print(q)

    1. [81, 63, 83]
    2. [63, 81, 83]
    3. [63, 83]
    4. [81, 83, 63]
    Answer

    (a) [81, 63, 83]

    items leave from the front in the order they joined (FIFO)

  3. 3.

    What is the first line this program prints? def enqueue(q, x):     q.append(x) def dequeue(q):     if len(q) == 0:         return 'Underflow'     return q.pop(0) q = [] enqueue(q, 55) enqueue(q, 58) enqueue(q, 75) print(dequeue(q)) print(dequeue(q)) enqueue(q, 91) print(dequeue(q)) enqueue(q, 19) print(q)

    1. 55
    2. 19
    3. None
    4. 58
    Answer

    (a) 55

    dequeue() removes the item at the front: the earliest one still waiting

Section B · short answer

  1. 4.

    What is a queue? Give an example from daily life.

    Answer

    A linear data structure in which items join at the rear and leave from the front (FIFO); e.g. people in a line at a ticket counter.

  2. 5.

    What does this program print? Write each line in order, separated by commas. def enqueue(q, x):     q.append(x) def dequeue(q):     if len(q) == 0:         return 'Underflow'     return q.pop(0) q = [] enqueue(q, 28) enqueue(q, 67) print(dequeue(q)) print(dequeue(q)) print(dequeue(q)) enqueue(q, 11) print(dequeue(q)) enqueue(q, 21) enqueue(q, 10) print(q)

    Answer

    28, 67, Underflow, 11, [21, 10]

    FIFO: each dequeue takes the earliest item still in the queue

Section C · long answer

  1. 6.

    Write a menu-driven program to implement a queue using a list, with enqueue, dequeue, peek and display.

    Answer

    q = []; enqueue: q.append(x); dequeue: if q: print(q.pop(0)) else print('Underflow'); peek: q[0] if q else 'Empty'; display: print(q). A while loop shows the menu.

Fresh sheets for your child

In the app, every Queue sheet is new: the app remembers the questions your child has already had and leaves them out. Print the sheet as a PDF, or use notebook mode and write the answers in a notebook.

Coming soon for Android and iPhone.

More Class 12 Computer Science