50 Data Structures MCQs with Answers

• Last Updated : 22 Feb, 2022

 Question 1
Which one of the following is an application of Stack Data Structure?
 A Managing function calls B The stock span problem C Arithmetic expression evaluation D All of the above
Stack    Stack    50 Data Structures MCQs with Answers
Discuss it

Question 1 Explanation:
 Question 2
Which one of the following is an application of Queue Data Structure?
 A When a resource is shared among multiple consumers. B When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes C Load Balancing D All of the above
Queue    50 Data Structures MCQs with Answers
Discuss it

Question 2 Explanation:
 Question 3
Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?
 A Insertion Sort B Quick Sort C Heap Sort D Merge Sort
Discuss it

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. http://www.geeksforgeeks.org/merge-sort-for-linked-list/
 Question 4
Which of the following is true about linked list implementation of stack?
 A In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end. B In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning. C Both of the above D None of the above
Stack    Stack    50 Data Structures MCQs with Answers
Discuss it

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?
 A In adjacency list representation, space is saved for sparse graphs. B 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. C Adding a vertex in adjacency list representation is easier than adjacency matrix representation. D All of the above
Graph    50 Data Structures MCQs with Answers
Discuss it

Question 5 Explanation:
 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
 A Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT B Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR C Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT D Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT
Queue    50 Data Structures MCQs with Answers
Discuss it

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?
 A 46, 42, 34, 52, 23, 33 B 34, 42, 23, 52, 33, 46 C 46, 34, 42, 23, 52, 33 D 42, 46, 33, 23, 34, 52
Hash    50 Data Structures MCQs with Answers
Discuss it

 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? (GATE CS 2005)

 A An array of 50 numbers B An array of 100 numbers C An array of 500 numbers D A dynamically allocated array of 550 numbers
Array    50 Data Structures MCQs with Answers
Discuss it

Question 8 Explanation:
 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?
 A A B B C C D D
Hash    50 Data Structures MCQs with Answers
Discuss it

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?
 A 7 5 1 0 3 2 4 6 8 9 B 0 2 4 3 1 6 5 9 8 7 C 0 1 2 3 4 5 6 7 8 9 D 9 8 6 4 2 3 0 1 5 7
Binary Search Trees    50 Data Structures MCQs with Answers
Discuss it

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.
My Personal Notes arrow_drop_up