Top 50 Data Structures MCQs with Answers

DSA has been one of the most popular go-to topics for any interview, be it college placements, software developer roles, or any other technical roles for freshers and experienced to land a decent job. So here we are, with the Top 50 most asked DSA MCQ questions to help you sail through your technical rounds.
More on DSA…

Question 1
Which one of the following is an application of Stack Data Structure?
Cross
Managing function calls
Cross
The stock span problem
Cross
Arithmetic expression evaluation
Tick
All of the above


Question 2

Which one of the following is an application of Queue Data Structure?

Cross

When a resource is shared among multiple consumers.

Cross

When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes

Cross

Load Balancing

Tick

All of the above



Question 2-Explanation: 

(A) When a resource is shared among multiple consumers: In scenarios where a resource (such as a printer, CPU time, or database connection) needs to be shared among multiple consumers or processes, a queue data structure can be used. Each consumer can enqueue their requests for the resource, and the resource can be allocated to them in the order of their requests by dequeuing from the queue. This ensures fair access to the shared resource and prevents conflicts or resource contention.

(B) When data is transferred asynchronously between two processes: When data is transferred asynchronously between two processes or systems, a queue can be used as a buffer or intermediary storage. One process enqueues the data to be sent, while the other process dequeues and processes the received data. The queue allows for decoupling the rate of data production from data consumption, ensuring smooth and efficient communication between the processes.

(C) Load Balancing: Load balancing is the practice of distributing workloads across multiple resources to optimize performance and utilization. A queue data structure can be used in load-balancing algorithms to manage incoming requests or tasks. The requests are enqueued in the queue, and the load balancer can dequeue and assign them to available resources based on various criteria (e.g., round-robin, least connections). This helps distribute the workload evenly across the resources, preventing overload and maximizing throughput.

Hence (D) is the correct option. 

Question 3

Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?

Cross

Insertion Sort

Cross

Quick Sort

Cross

Heap Sort

Tick

Merge Sort



Question 3-Explanation: 

Both Merge sort and Insertion sort can be used for linked lists. The slow random-access performance of a linked list makes other algorithms (such as quicksort) perform poorly, and others (such as heapsort) completely impossible. Since worst case time complexity of Merge Sort is O(nLogn) and Insertion sort is O(n^2), merge sort is preferred. See following for implementation of merge sort using Linked List.

Question 4
Which of the following is true about linked list implementation of stack?
Cross
In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end.
Cross
In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning.
Cross
Both of the above
Tick
None of the above


Question 4-Explanation: 
To keep the Last In First Out order, a stack can be implemented using linked list in two ways: a) In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from beginning. b) In push operation, if new nodes are inserted at the end of linked list, then in pop operation, nodes must be removed from end.
Question 5
Which of the following is an advantage of adjacency list representation over adjacency matrix representation of a graph?
Cross
In adjacency list representation, space is saved for sparse graphs.
Cross
DFS and BSF can be done in O(V + E) time for adjacency list representation. These operations take O(V^2) time in adjacency matrix representation. Here is V and E are number of vertices and edges respectively.
Cross
Adding a vertex in adjacency list representation is easier than adjacency matrix representation.
Tick
All of the above


Question 6

Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are

Tick

Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT

Cross

Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR

Cross

Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT

Cross

Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT



Question 6-Explanation: 

Suppose we start filling the queue.

Let the maxQueueSize ( Capacity of the Queue) is 4.So the size of the array which is used to implement this circular queue is 5, which is n. In the beginning when the queue is empty, FRONT and REAR point to 0 index in the array. REAR represents insertion at the REAR index. FRONT represents deletion from the FRONT index.

enqueue(\"a\"); REAR = (REAR+1)%5; ( FRONT = 0, REAR = 1)

enqueue(\"b\"); REAR = (REAR+1)%5; ( FRONT = 0, REAR = 2)

enqueue(\"c\"); REAR = (REAR+1)%5; ( FRONT = 0, REAR = 3)

enqueue(\"d\"); REAR = (REAR+1)%5; ( FRONT = 0, REAR = 4)

Now the queue size is 4 which is equal to the maxQueueSize. Hence overflow condition is reached.

Now, we can check for the conditions.

When Queue Full :
( REAR+1)%n = (4+1)%5 = 0
FRONT is also 0. Hence ( REAR + 1 ) %n is equal to FRONT.

When Queue Empty :

REAR was equal to FRONT when empty ( because in the starting before filling the queue FRONT = REAR = 0 )

Hence Option A is correct. 

Question 7

A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below. 

 

Which one of the following choices gives a possible order in which the key values could have been inserted in the table?

Cross

46, 42, 34, 52, 23, 33

Cross

34, 42, 23, 52, 33, 46

Tick

46, 34, 42, 23, 52, 33

Cross

42, 46, 33, 23, 34, 52



Question 7-Explanation: 

Here linear probing is used with the hash function h(k)=k mod 10.

Let's analyze all the options carefully:

KeyABCD
0    
1    
242424242
352232333
434343423
523525234
646334646
733463352
8    
9    

After analyzing all the options (C) is the correct possible order in which the key values could have been inserted in the table

(A) doesn’t create the hash table as the element 52 appears before 23 in this sequence.
(B) doesn't create the hash table as the element 33 appears before 46 in this sequence.
(C)create the hash table as the element 42, 23 and 34 appear before 52 and 33, and 46 appears before 33.
(D)doesn't create the hash table as element 33 appears before 23 in this sequence.

Question 8

A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?
 

Tick

An array of 50 numbers
 

Cross

An array of 100 numbers
 

Cross

An array of 500 numbers
 

Cross

A dynamically allocated array of 550 numbers
 



Question 8-Explanation: 

An array of 50 numbers is correct.

Question 9

The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function h(k) = k mod 10 and linear probing. What is the resultant hash table?

 

Cross

A

Cross

B

Tick

C

Cross

D



Question 9-Explanation: 

To get the idea of open addressing concept, you can go through below lines from Wikipedia . Open addressing, or closed hashing, is a method of collision resolution in hash tables. With this method a hash collision is resolved by probing, or searching through alternate locations in the array (the probe sequence) until either the target record is found, or an unused array slot is found, which indicates that there is no such key in the table. Well known probe sequences include: linear probing in which the interval between probes is fixed--often at 1. quadratic probing in which the interval between probes increases linearly (hence, the indices are described by a quadratic function). double hashing in which the interval between probes is fixed for each record but is computed by another hash function.

Question 10
Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?
Cross
7 5 1 0 3 2 4 6 8 9
Cross
0 2 4 3 1 6 5 9 8 7
Tick
0 1 2 3 4 5 6 7 8 9
Cross
9 8 6 4 2 3 0 1 5 7


Question 10-Explanation: 
In-order traversal of a BST gives elements in increasing order. So answer c is correct without any doubt.
There are 50 questions to complete.


  • Last Updated : 26 Sep, 2023

Share your thoughts in the comments
Similar Reads