MCQ DS
MCQ DS
18.Which of the following data structures allow insertion and deletion from both
ends?
Stack
Deque
Queue
Strings
19.What will be the output of the following code snippet?
void solve() {
deque<int> dq;
for(int i = 1; i <= 5; i++) {
if(i % 2 == 0) {
dq.push_back(i);
}
else {
dq.push_front(i);
}
}
for(auto x: dq) {
cout << x << " ";
}
cout << endl;
}
123 45
543 21
135 24
531 24
20.Which of the following sorting algorithms provide the best time complexity in
the worst-case scenario?
Merge Sort
Quick Sort
Bubble Sort
Selection Sort
21.What is the maximum number of swaps that can be performed in the Selection
Sort algorithm?
n-1
n
1
n-2
23.What will be the best sorting algorithm, given that the array elements are small ?
Bubble Sort
Merge Sort
Counting Sort
Heap Sort
26.Which of the following algorithms are used for string and pattern matching
problems?
Z Algorithm
Rabin Karp Algorithm
KMP Algorithm
All of the above
28.Which of the following algorithms are useful for processing queries on trees?
Centroid Decomposition.
Heavy Light Decomposition.
Both (A) and (B).
Neither (A) nor (B).
30.Kruskal’s Algorithm for finding the Minimum Spanning Tree of a graph is a kind
of a?
DP Problem.
Greedy Algorithm.
Adhoc Problem.
None of the above.
32.Maps in C++ are implemented using which of the following data structures?
Red-Black Trees.
Binary Search Trees.
AVL Trees.
Hash Tables.
38.What will be the value of “sum” after the following code snippet terminates?
void solve(ListNode* root) {
/*
The LinkedList is defined as:
root-> val = value of the node
root-> next = address of next element from the node
The List is 1 -> 2 -> 3 -> 4 -> 5
*/
int sum = 0;
while(root -> next != NULL) {
sum += root -> val;
root = root -> next;
}
cout << sum << endl;
}
10
20
5
1
39.Which of the following can be done with LinkedList?
Implementation of Stacks and Queues
Implementation of Binary Trees
Implementation of Data Structures that can simulate Dynamic Arrays
All of the above
41.What is the maximum number of children a node can have in an n-ary tree?
2
0
1
n
44.In what time complexity can we find the diameter of a binary tree optimally?
O(V + E)
O(V)
O(E)
O(V * logE)
46. In a graph of n nodes and n edges, how many cycles will be present?
Exactly 1
At most 1
At most 2
Depends on the graph
47. A node in a tree, such that removing it splits the tree into forests, with size of
each connected component being not greater than n / 2 is called?
Center
Diameter
Centroid
Path
48. Which of the following algorithms are used to find the shortest path from a
source node to all other nodes in a weighted graph?
BFS.
Djikstra’s Algorithm.
Prims Algorithm.
Kruskal’s Algorithm.
49. What is the best time complexity we can achieve to precompute all-pairs
shortest paths in a weighted graph?
O(n^3)
O(n^2)
O(n)
O(n^4)
50. Which data structure is mainly used for implementing the recursive algorithm?
Queue
Stack
Array
List