Q: 1 A normal queue, if implemented using an array of size N, gets full when ________.
(FRONT+1)%N==FRONT
(REAR+1)%N==REAR
REAR==N-1
FRONT==-1
[ Option C ]
In a normal or linear queue implemented using an array of size N, the queue becomes full when the value of REAR reaches the last index of the array, that is N−1.
Q: 2 After performing following set of operations, what does the final list look contain?
InsertFront(10);
InsertFront(20);
InsertRear(30);
DeleteFront();
InsertRear(40);
InsertRear(10);
DeleteRear();
InsertRear(15);
Display();
10 30 10 15
20 30 40 15
10 30 40 15
None of the above
[ Option C ]
These operations are performed on a double-ended queue (deque) or a list that allows insertion and deletion at both front and rear.
Now apply the operations one by one and show the list after each step:
So, the final list is 10 30 40 15.
Q: 3 If circular queue is implemented using array having size MAX_SIZE in which array index start with 0, front points to the first element in the queue, and rear points to the last element in the queue. Which one of the following conditions is used to specify that the circular queue is empty?
front = rear = -1
front = rear =0
front = rear +1
None of the above
[ Option A ]
In a circular queue implemented using an array, the queue is considered empty when there are no elements stored in it. The most common and standard way to represent an empty circular queue is if front=rear=-1.
When the circular queue is first created, it contains no elements. To show this, both front and rear are initialized to -1. As soon as we insert the first element both front and rear becomes 0. When all elements are deleted again, we reset them to -1 to show the queue is empty.
Q: 4 Consider the following sequence of operations on an empty stack.
push(54); push(52); pop(); push(55); push(62); s=pop();
Consider the following sequence of operations on an empty queue.
enqueue(21); enqueue(24); dequeue(); enqueue(28); enqueue(32); q=dequeue();
The value of s+q is _______.
83
86
75
94
[ Option B ]
First, consider the stack operations (LIFO). The stack is initially empty. After push(54) and push(52), the stack becomes [54, 52]. The pop() operation removes 52. Then push(55) and push(62) make the stack [54, 55, 62]. Finally, s=pop() removes the top element 62, so s=62.
Next, consider the queue operations (FIFO). The queue is initially empty. After enqueue(21) and enqueue(24), the queue becomes [21, 24]. The dequeue() operation removes 21. Then enqueue(28) and enqueue(32) make the queue [24, 28, 32]. Finally, q = dequeue() removes 24, so q=24.
Therefore, s+q = 62+24 = 86
Q: 5 The minimum number of stacks needed to implement a queue is:
2
3
1
Not possible through stack
[ Option A ]
A queue follows the FIFO (First In First Out) principle, whereas a stack follows the LIFO (Last In First Out) principle.
To implement a queue using stacks, we need two stacks. One stack is used for enqueue operations, and the other stack is used for dequeue operations.
By transferring elements between the two stacks, the order of elements is reversed, which helps achieve FIFO behavior.
Q: 6 The five items: A, B, C, D, and E are pushed in a stack, one after other starting from A. The stack is popped four items and each element is inserted in a queue. The two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack. The popped item is _____.
C
D
B
A
[ Option B ]
First, the elements A, B, C, D, E are pushed onto the stack in this order. Since a stack follows LIFO, after all pushes the stack (Top → Bottom) becomes: E, D, C, B, A.
| Operation | Stack Status (Top → Bottom) | Queue |
|---|---|---|
| Push A | A | — |
| Push B | B, A | — |
| Push C | C, B, A | — |
| Push D | D, C, B, A | — |
| Push E | E, D, C, B, A | — |
Now, four elements are popped from the stack and inserted into a queue.
| Operation | Stack Status (Top → Bottom) | Queue Status (Front → Rear) |
|---|---|---|
| Pop E → Enqueue | D, C, B, A | E |
| Pop D → Enqueue | C, B, A | E, D |
| Pop C → Enqueue | B, A | E, D, C |
| Pop B → Enqueue | A | E, D, C, B |
Next, two elements are deleted from the queue and pushed back on the stack.
| Operation | Stack Status (Top → Bottom) | Queue Status (Front → Rear) |
|---|---|---|
| Dequeue E → Push | E, A | D, C, B |
| Dequeue D → Push | D, E, A | C, B |
Finally, one item is popped from the stack, which removes the top element D.
| Operation | Stack Status (Top → Bottom) | Popped Item |
|---|---|---|
| Pop | E, A | D |
Q: 7 The data structure in which data are added at the rear and deleted from front is called
Stack
Queue
Linked list
None of the above
[ Option B ]
A data structure in which elements are inserted at the rear and deleted from the front follows the FIFO (First In, First Out) principle. This is exactly how a queue works. In a queue, new data always enters from the rear (back or end), and the oldest data is removed from the front.
Q: 8 A linear list in which elements can be added or removed at either end but not in the middle, is called ___________.
Priority Queue
Threaded Binary Tree
Dequeue
Linked List
[ Option C ]
A Dequeue stands for Double Ended Queue. It is a linear data structure where:
In priority queue, elements are inserted in any order but removed based on priority, not position.
The threaded binary tree is type of binary tree optimized for in-order traversal, not a linear list.
The linked list allows insertions and deletions at any position, including the middle.
Q: 9 What is another name for the circular queue among the following options?
Rectangle buffer
Square buffer
Ring buffer
More than one of the above
[ Option C ]
In a normal Queue, we can insert elements until queue becomes full. But once queue becomes full, we cannot insert the next element even if there is a space in front of queue.
A Circular Queue is a type of queue in which the last position is connected back to the first position, forming a circle. This allows efficient use of memory by reusing empty spaces when elements are deleted.
Another common name for a circular queue is a Ring Buffer, because conceptually the storage forms a ring where the front and rear wrap around.
If we want to insert new element in circular queue using REAR end, then the value of REAR can be calculated as: REAR=(REAR+1)%CAPACITY
Similarly, when we want to delete existing element from the circular queue using FRONT end, then the value of FRONT can be calculated as: FRONT=(FRONT+1)%CAPACITY
Q: 10 A queue has configuration a, b, c, d. if you want to get the configuration d, c, b, a, you need a minimum of ___________.
2 deletions and 3 additions
3 deletions and 3 additions
4 deletions and 4 additions
None of the above
[ Option B ]
To reverse a queue from configuration [a, b, c, d] to [d, c, b, a] using only queue operations, the minimum required is 3 deletions and 3 additions.
| STEP | OPERATION | DEQUEUED ELEMENT | ENQUEUED ELEMENT | QUEUE STATUS |
|---|---|---|---|---|
| Initially | — | — | — | [a,b,c,d] |
| 1 | Dequeue | a | — | [b,c,d] |
| 2 | Dequeue | b | — | [c,d] |
| 3 | Dequeue | c | — | [d] |
| 4 | Enqueue | — | c | [d,c] |
| 5 | Enqueue | — | b | [d,c,b] |
| 6 | Enqueue | — | a | [d,c,b,a] |
Q: 11 A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?
Queue
Deque
Stack
Priority Queue
[ Option B ]
A Deque (Double-Ended Queue) is a data structure in which elements can be inserted and deleted at both ends, the front as well as the rear but not in the middle.
Q: 12 A liner list of elements in which deletion can be done from one end and insertion can take place only at the other end is known as:
Stack
Queue
Tree
Linked-List
[ Option B ]
A queue is a linear data structure in which insertion of elements is performed at one end called rear end and deletion of elements is performed from the other end called front end. This behavior follows the FIFO (First In, First Out) principle.
Q: 13 Queue data structure uses
FIFO
LIFO
LILO
None of the above
[ Option A ]
A queue is a linear data structure that manages elements in a specific order, like people waiting in line at a ticket counter, the first to arrive is served first. A queue follows the FIFO (First In, First Out) principle.
Q: 14 What is the another name for the circular queue among the following options?
Square buffer
Rectangle buffer
Ring buffer
None of the above
[ Option C ]
A Circular Queue is also commonly known as a Ring Buffer. It is a data structure that connects the last position back to the first, forming a circle, which allows efficient reuse of buffer space.
Same as queue the circular queue data structure follows the FIFO (First In, First Out) principle and is widely used in scenarios where fixed size buffer management is needed.
The circular queue is empty (underflow) when front == -1 and full (overflow) when (rear + 1) % capacity == front.
Q: 15 Which one of the following is the overflow condition if linear queue is implemented using an array with a size MAX_SIZE?
rear=MAX_SIZE-1
rear=MAX_SIZE
rear=front+1
None of the above
[ Option A ]
In a linear queue implemented using an array, overflow occurs when the rear index reaches the last valid index of the array. Since array indexing starts from 0, the last index is MAX_SIZE−1. Once rear becomes MAX_SIZE−1, no more elements can be inserted, even if elements at the front have been dequeued.
Q: 16 In the deque implementation, using singly linked list, what would be the time complexity of deleting an element from the rear end?
O(1)
O(N log N)
O(N)
None of the above
[ Option C ]
In a deque implemented using a singly linked list, deletion from the rear end is inefficient. Since the list is singly linked, you do not have a direct pointer to the previous node. To delete the last node, you must traverse the entire list from the start or head to find the second-last node. This traversal takes linear time, i.e., O(N).
Q: 17 Which of the following is not the type of queue?
Ordinary Queue
Single Ended Queue
Circular Queue
Priority Queue
[ Option B ]
Common types of queues include the ordinary or linear queue, circular queue, and priority queue.
Q: 18 Consider the following code.
void myFun(int n)
{
int *q = (int*)malloc(sizeof(int)*n);
int i;
enqueue(q,0);
enqueue(q,1);
for (i = 0; i < n; i++)
{
int a = dequeue(q);
int b = dequeue(q);
enqueue(q,b);
enqueue(q,a+b);
printf("%d ",a);
}
}
What does the function myFun do?
Prints numbers from 0 to n-1
Prints numbers from n-1 to 0
Prints first n Fibonacci numbers
Prints first n whole number
[ Option C ]
The function myFun(int n) uses a queue-based approach to generate numbers. Initially, two values 0 and 1 are enqueued into the queue.
Inside the loop, which runs n times, the function dequeues two elements a and b. It then enqueues b back into the queue, followed by a+b. This ensures that the next pair of numbers in the sequence is always available in the queue. During each iteration, the value of a is printed.
This process exactly follows the logic of generating the Fibonacci Sequence, where each number is the sum of the previous two numbers, starting from 0 and 1. Hence, the function prints the first n Fibonacci numbers.
Q: 19 Which one of the following is an application of queue data structure?
When a resource is shared among multiple consumers.
When data is transferred asynchronously between two processes.
Load balancing
All of the above
[ Option D ]
A queue data structure has several important applications in the real world. It is commonly used when a resource is shared among multiple consumers, as it manages access by processing requests in a First-In-First-Out (FIFO) manner. This ensures fairness by servicing requests in the order they arrive.
Queues are also used when data is transferred asynchronously between two processes, acting as a buffer to hold data until the receiving process is ready, as seen in the producer-consumer problem with message queues.
Another significant use of queues is in load balancing, where tasks or workloads are distributed evenly across multiple servers or systems by holding tasks in a queue until resources are available to process them.
Overall, queues play a vital role in managing resource sharing, buffering asynchronous data transfer, and balancing workload efficiently in computing systems.
Q: 20 Which one of the following is not the application of the queue data structure?
Data is transferred asynchronously
Resource is shared between various system
Balancing of symbols
More than one of the above
[ Option C ]
A queue is a linear data structure that follows the FIFO (First In, First Out) principle, meaning the first element added is the first one to be removed. There are several applications of queue data structure.
Q: 21 If the elements A, B, C and D are placed in a queue and are deleted one at a time, in what order will they be removed?
DCBA
DCAB
ABDC
ABCD
[ Option D ]
A queue follows the FIFO (First In, First Out) principle. This means the element that is inserted first is the one that is removed first. Since the elements A, B, C, and D are placed in the queue in that order, they will also be deleted in the same order: A first, then B, then C, and finally D.
Q: 22 Which of the following determines the need for the circular queue?
Access the queue using priority
Avoid wastage of memory
Follow the FIFO principle
More than one of the above
[ Option B ]
A Circular Queue is mainly used to avoid wastage of memory that occurs in a simple linear queue when the front moves forward after deletions but empty spaces at the beginning cannot be reused.
Q: 23 A linear data structure in which insertion and deletion operations can be performed from both the ends is
Queue
Circular Queue
Deque
More than one of the above
[ Option C ]
A linear data structure that allows insertion and deletion from both the front and the rear is called a Deque (Double-Ended Queue).
A deque is special because it allows:
Q: 24 Which of the following principle does queue use?
LIFO principle
FIFO principle
Linear tree
Ordered array
[ Option B ]
A queue is a linear data structure that follows the FIFO (First In, First Out) principle. This means the first added element to the queue will be the first one to be removed. There are mainly two operations enqueue (adding an element at the rear end) and dequeue (removing an element from the front end).
Q: 25 The necessary condition to be checked before deletion from the queue is
Overflow
Underflow
Rear value
None of the above
[ Option B ]
Before deleting an element from a queue, we must ensure that the queue is not empty. If the queue is empty, deletion is not possible, and this condition is called underflow.
Q: 26 Which data structure is the best for implementing a priority queue?
Linked list
Array
Binary heap
None of the above
[ Option C ]
A priority queue works by always removing the element with the highest priority first, not necessarily the first inserted one.
The best data structure for implementing a priority queue is the Binary Heap because this organizes data in such a way that both insertion and deletion of the highest-priority element take only O(log n) time, making it far more efficient and suitable.
Q: 27 Suppose a circular queue is implemented using array of capacity N. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = -1. The conditions to detect queue full is:
(REAR+1)%N==FRONT
(REAR+1)%N==REAR
REAR==FRONT
Both (A) and (C)
[ Option A ]
In a circular queue implemented using an array of capacity N, the queue is considered full when the next position of REAR after circular increment becomes equal to FRONT. This condition indicates that there is no empty space left for inserting a new element.
Q: 28 The seven elements A, B, C, D, E, F and G are pushed onto a stack in reverse order, i.e., starting from G. The stack is popped five times and each element is inserted into a queue. Two elements are deleted from the queue and pushed back onto the stack. Now, one element is popped from the stack. The popped item is ______.
B
A
G
F
[ Option A ]
Push elements onto stack in reverse order starting from G.
| Operation | Stack Status (Top → Bottom) |
|---|---|
| Push G | G |
| Push F | F, G |
| Push E | E, F, G |
| Push D | D, E, F, G |
| Push C | C, D, E, F, G |
| Push B | B, C, D, E, F, G |
| Push A | A, B, C, D, E, F, G |
Pop 5 elements from stack and enqueue into queue.
| Operation | Stack Status (Top → Bottom) | Queue Status (Front → Rear) |
|---|---|---|
| Pop A and Enqueue. | B, C, D, E, F, G | A |
| Pop B and Enqueue. | C, D, E, F, G | A, B |
| Pop C and Enqueue. | D, E, F, G | A, B, C |
| Pop D and Enqueue. | E, F, G | A, B, C, D |
| Pop E and Enqueue. | F, G | A, B, C, D, EA, B, C, D, E |
Dequeue 2 elements and push back onto stack.
| Operation | Stack Status (Top → Bottom) | Queue Status (Front → Rear) |
|---|---|---|
| Dequeue A and Push. | A, F, G | B, C, D, E |
| Dequeue B and Push. | B, A, F, G | C, D, E |
Finally pop from stack.
| Operation | Stack Status (Top → Bottom) | Popped Item |
|---|---|---|
| Pop | A, F, G | B |
Q: 29 Which one of the following is not the type of queue?
Linear queue
Circular queue
Double-ended queue
None of the above
[ Option D ]
A queue is a linear data structure that follows the FIFO (First In, First Out) principle. Over time, several variations of queues have been developed to solve different problems.
TYPES OF QUEUES:
Linear Queue: The simplest type of queue, where elements are inserted at the rear and deleted from the front.
Circular Queue: A variation of the linear queue, where the last position is connected back to the first to form a circle, allowing efficient use of space.
Double-ended Queue (Deque): A queue where insertion and deletion can be done from both ends (front and rear). It supports more flexible operations than simple linear or circular queues.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.