CBSE Class 12
Computer Science
04 Queue
30
Total
0
Attempted
0
Correct
0
Wrong
00:00:00
Q-1
Consider the following Python implementation of a queue using a list. What will be printed?
Medium
Implementation of Queue using Python
Reference Code
```python
q = []
q.append(10)
q.append(20)
q.append(30)
q.pop(0)
print(q)
A
[20, 30]
B
[10, 20]
C
[30]
D
[10, 30]
Answer: [20, 30]
Explanation: append() inserts elements at rear. pop(0) removes the first element (10), leaving [20,30].
Q-2
A queue initially contains [5, 10, 15]. After performing enqueue(20), dequeue(), enqueue(25), what is the final queue?
Medium
Operations on Queue
A
[10,15,20]
B
[10,15,20,25]
C
[5,10,15,25]
D
[15,20,25]
Answer: [10,15,20,25]
Explanation: enqueue(20) → [5,10,15,20]; dequeue removes 5 → [10,15,20]; enqueue(25) → [10,15,20,25].
Q-3
Which Python code correctly performs a dequeue operation when implementing a queue using a list?
Medium
Operations on Queue
A
q.pop()
B
q.remove()
C
q.pop(0)
D
del q[-1]
Answer: q.pop(0)
Explanation: Queue follows FIFO. pop(0) removes the element from the front.
Q-4
What will be printed by the following code?
Medium
Implementation of Queue using Python
Reference Code
```python
q=[2,4,6]
q.append(8)
print(q.pop(0), q)
A
2 [2,4,6,8]
B
4 [6,8]
C
8 [2,4,6]
D
2 [4,6,8]
Answer: 2 [4,6,8]
Explanation: append(8) → [2,4,6,8]; pop(0) removes 2 leaving [4,6,8].
Q-5
Which data structure principle does a queue follow?
Easy
Introduction to Queue
A
FIFO
B
LIFO
C
FILO
D
LILO
Answer: FIFO
Explanation: Queue follows First-In First-Out.
Q-6
Consider the queue operations below. What will be printed?
Medium
Operations on Queue
Reference Code
```python
q=[1,2]
q.append(3)
q.append(4)
q.pop(0)
print(q)
A
[2,3,4]
B
[2,3,4]
C
[1,2,3,4]
D
[3,4]
Answer: [2,3,4]
Explanation: append 3,4 → [1,2,3,4]; pop(0) removes 1 → [2,3,4].
Q-7
What will be printed?
Medium
Introduction to Deque
Reference Code
```python
from collections import deque
d=deque([10,20,30])
d.append(40)
print(d)
A
deque([10,20,30])
B
deque([20,30,40])
C
deque([10,20,30,40])
D
Error
Answer: deque([10,20,30,40])
Explanation: append adds element to the right end of deque.
Q-8
Which deque operation removes an element from the left side?
Medium
Implementation of Deque Using Python
A
pop()
B
remove()
C
delete()
D
popleft()
Answer: popleft()
Explanation: popleft() removes the element from the left end.
Q-9
What will be printed?
Medium
Implementation of Deque Using Python
Reference Code
```python
from collections import deque
d=deque([5,10])
d.appendleft(2)
print(d)
A
deque([2,5,10])
B
deque([5,10,2])
C
deque([10,5,2])
D
Error
Answer: deque([2,5,10])
Explanation: appendleft inserts element at the left end.
Q-10
Which method inserts an element at the rear of a queue implemented using Python list?
Easy
Implementation of Queue using Python
A
push()
B
append()
C
insert()
D
add()
Answer: append()
Explanation: append() adds element to rear of queue.
Q-11
What will be printed?
Medium
Implementation of Queue using Python
Reference Code
```python
q=[3,6,9]
q.append(12)
q.pop(0)
q.append(15)
print(q)
A
[3,6,9,12,15]
B
[6,9,12]
C
[6,9,12,15]
D
[3,9,12,15]
Answer: [6,9,12,15]
Explanation: append 12 → [3,6,9,12]; pop(0) removes 3 → [6,9,12]; append 15 → [6,9,12,15].
Q-12
What will be printed?
Medium
Implementation of Deque Using Python
Reference Code
```python
from collections import deque
d=deque([1,2,3])
d.pop()
print(d)
A
deque([1,2])
B
deque([2,3])
C
deque([3])
D
deque([1,2])
Answer: deque([1,2])
Explanation: pop() removes element from right side.
Q-13
Which operation removes the front element of a queue?
Easy
Operations on Queue
A
Dequeue
B
Push
C
Peek
D
Insert
Answer: Dequeue
Explanation: Dequeue removes the front element.
Q-14
Which Python module provides deque implementation?
Easy
Introduction to Deque
A
math
B
collections
C
sys
D
array
Answer: collections
Explanation: Deque is provided by collections module.
Q-15
What will be printed?
Medium
Operations on Queue
Reference Code
```python
q=[7,8,9]
print(q[0])
A
9
B
8
C
7
D
Error
Answer: 7
Explanation: First element represents front of queue.
Q-16
What will be printed?
Medium
Implementation of Deque Using Python
Reference Code
```python
from collections import deque
d=deque([4,6,8])
d.appendleft(2)
d.pop()
print(d)
A
deque([2,4,6,8])
B
deque([4,6])
C
deque([2,4,6])
D
deque([2,4,6])
Answer: deque([2,4,6])
Explanation: appendleft(2) → [2,4,6,8]; pop removes 8 → [2,4,6].
Q-17
If queue = [10,20,30] and dequeue() is performed once, what remains?
Easy
Operations on Queue
A
[20,30]
B
[10,20]
C
[30]
D
[]
Answer: [20,30]
Explanation: Front element 10 is removed.
Q-18
Which deque operation inserts element at the right side?
Easy
Implementation of Deque Using Python
A
appendleft()
B
append()
C
insert()
D
push()
Answer: append()
Explanation: append() inserts element at right end.
Q-19
What will be printed?
Medium
Operations on Queue
Reference Code
```python
q=[2,4,6]
while q:
print(q.pop(0), end=" ")
A
6 4 2
B
4 6 2
C
2 4 6
D
Error
Answer: 2 4 6
Explanation: Queue removes elements in FIFO order.
Q-20
Which operation checks the front element without removing it?
Medium
Operations on Queue
A
Pop
B
Insert
C
Remove
D
Peek
Answer: Peek
Explanation: Peek returns front element without deletion.
Q-21
Which structure allows insertion and deletion from both ends?
Medium
Introduction to Deque
A
Deque
B
Stack
C
Queue
D
Tree
Answer: Deque
Explanation: Deque (double-ended queue) allows both operations.
Q-22
What happens when pop(0) is executed on an empty list used as queue?
Medium
Implementation of Queue using Python
A
Returns None
B
Raises IndexError
C
Returns 0
D
Creates new element
Answer: Raises IndexError
Explanation: Removing element from empty list raises IndexError.
Q-23
Which deque operation removes the rightmost element?
Easy
Implementation of Deque Using Python
A
popleft()
B
remove()
C
pop()
D
delete()
Answer: pop()
Explanation: pop() removes element from right end.
Q-24
Which statement correctly creates an empty deque?
Easy
Implementation of Deque Using Python
A
deque[]
B
deque{}
C
deque()
D
deque<>
Answer: deque<>
Explanation: deque() creates an empty deque object.
Q-25
Which operation inserts an element into a queue?
Easy
Operations on Queue
A
Enqueue
B
Dequeue
C
Peek
D
Delete
Answer: Enqueue
Explanation: Enqueue inserts element into queue.
Q-26
Which deque method removes the first element?
Easy
Implementation of Deque Using Python
A
pop()
B
popleft()
C
remove()
D
delete()
Answer: popleft()
Explanation: popleft() removes element from left side.
Q-27
What will be printed?
Medium
Implementation of Deque Using Python
Reference Code
```python
from collections import deque
d=deque([3,6,9])
d.appendleft(1)
d.append(12)
print(d)
A
deque([3,6,9,1,12])
B
deque([6,9,1,12])
C
deque([1,3,6,9,12])
D
deque([12,9,6,3,1])
Answer: deque([1,3,6,9,12])
Explanation: appendleft adds to left, append adds to right.
Q-28
Which structure is ideal for implementing task scheduling?
Medium
Introduction to Queue
A
Stack
B
Tree
C
Deque
D
Queue
Answer: Queue
Explanation: Queues are used in scheduling because they process tasks in order.
Q-29
If queue=[4,8,12] and enqueue(16) then dequeue() is executed, what remains?
Medium
Operations on Queue
A
[8,12,16]
B
[4,8,12,16]
C
[8,12]
D
[12,16]
Answer: [8,12,16]
Explanation: enqueue 16 → [4,8,12,16]; dequeue removes 4.
Q-30
Which structure supports efficient insertion and deletion from both ends in Python?
Medium
Introduction to Deque
A
list
B
set
C
tuple
D
deque
Answer: set
Explanation: Deque is optimized for fast operations at both ends.
◀
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
▶