Explore topic-wise MCQs in Data Structures Mcqs.

This section includes 56 Mcqs, each offering curated multiple-choice questions to sharpen your Data Structures Mcqs knowledge and support exam preparation. Choose a topic below to get started.

1.

What will be the value stored in arr[5] when the following code is executed?

A. 14
B. 42
C. 132
D. 429
Answer» C. 132
2.

Which line should be inserted in the blank to complete the following dynamic programming implementation of the maximum sub-array sum problem?

A. Max_num(sum[idx 1] + arr[idx], arr[idx])
B. Sum[idx 1] + arr[idx]
C. Min_num(sum[idx 1] + arr[idx], arr[idx])
D. Arr[idx]
Answer» B. Sum[idx 1] + arr[idx]
3.

Which of the following errors will occur when the below code is executed?

A. Segmentation fault
B. Array size too large
C. Integer value out of range
D. None of the mentioned
Answer» D. None of the mentioned
4.

Which of the following implementations of Catalan numbers has the largest space complexity(Don t consider the stack space)?

A. Dynamic programming
B. Binomial coefficients
C. Recursion
D. All of the mentioned
Answer» B. Binomial coefficients
5.

Which of the following is the longest common subsequence between the strings hbcfgmnapq and cbhgrsfnmq ?

A. Hgmq
B. Cfnq
C. Bfmq
D. All of the mentioned
Answer» E.
6.

Which of the following strings is a palindromic subsequence of the string ababcdabba ?

A. Abcba
B. Abba
C. Abbbba
D. All of the mentioned
Answer» E.
7.

You are given a rod of length 10 and the following prices.length price 1 2 2 5 3 6 4 9 5 9 6 17 7 17 8 18 9 20 10 22Which of these pieces give the maximum price?

A. {1,2,7}
B. {10}
C. {2,2,6}
D. {1,4,5}
Answer» D. {1,4,5}
8.

You are given a rod of length 5 and the prices of each length are as follows:length price 1 2 2 5 3 6 4 9 5 9What is the maximum value that you can get after cutting the rod and selling the pieces?

A. 10
B. 11
C. 12
D. 13
Answer» D. 13
9.

Complete the following code for Kadane s algorithm:

A. Max_num(sum, sum + arr[idx])
B. Sum
C. Sum + arr[idx].
D. Max_num(sum,ans)
Answer» E.
10.

Complete the following dynamic programming implementation of the longest increasing subsequence problem:

A. Tmp_max = LIS[j].
B. LIS[i] = LIS[j].
C. LIS[j] = tmp_max
D. Tmp_max = LIS[i].
Answer» B. LIS[i] = LIS[j].
11.

Consider the following assembly line problem.For the optimal solution which should be the starting assembly line?

A. Line 1
B. Line 2
C. All of the mentioned
D. None of the mentioned
Answer» C. All of the mentioned
12.

You are given infinite coins of N denominations v1, v2, v3, ..,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. What is the time complexity of a dynamic programming implementation used to solve the coin change problem?

A. O(N)
B. O(S)
C. O(N^2)
D. O(S*N)
Answer» E.
13.

Fill in the blank to complete the code.

A. Lookup[tmp] = min_coins
B. Min_coins = lookup[tmp]
C. Break
D. Continue
Answer» C. Break
14.

The recursive formula for Catalan number is given by Cn = Ci*C(n-i).Consider the following dynamic programming implementation for Catalan numbers. Which of the following lines completes the below code?

A. Arr[i] = arr[j] * arr[k],
B. Arr[j] += arr[i] * arr[k],
C. Arr[i] += arr[j] * arr[k].
D. Arr[j] = arr[i] * arr[k],
Answer» D. Arr[j] = arr[i] * arr[k],
15.

What is the output of the following implementation of Kadane s algorithm?

A. 1
B. -1
C. -2
D. None of the mentioned
Answer» E.
16.

What is the output of the following naive method used to find the maximum sub-array sum?

A. 6
B. 9
C. 7
D. None of the mentioned
Answer» D. None of the mentioned
17.

What is the space complexity of Kadane s algorithm?

A. O(1)
B. O(n)
C. O(n^2)
D. None of the mentioned
Answer» B. O(n)
18.

What is the time complexity of the Wagner Fischer algorithm where m and n are the lengths of the two strings?

A. O(1)
B. O(n+m)
C. O(mn)
D. O(nlogm)
Answer» D. O(nlogm)
19.

What is the value stored in arr[2][2] when the following code is executed?

A. 1
B. 2
C. 3
D. 4
Answer» C. 3
20.

What is the value stored in arr[2][3] when the following code is executed?

A. 1
B. 2
C. 3
D. 4
Answer» B. 2
21.

What is the value stored in arr[3][3] when the below code is executed?

A. 1
B. 2
C. 3
D. 4
Answer» D. 4
22.

What is the value stored in arr[3][3] when the following code is executed?

A. 2
B. 3
C. 4
D. 5
Answer» B. 3
23.

What is the value stored in LIS[5] after the following program is executed?

A. 2
B. 3
C. 4
D. 5
Answer» D. 5
24.

What is the value stored in max_val[5] after the following program is executed?

A. 12
B. 27
C. 10
D. 17
Answer» B. 27
25.

What is the value stored in sum[4] after the following program is executed?

A. 28
B. 25
C. 22
D. 12
Answer» D. 12
26.

What is the value stored in t1[2] when the following code is executed?

A. 16
B. 18
C. 20
D. 22
Answer» D. 22
27.

What is the value stored in t2[3] when the following code is executed?

A. 19
B. 23
C. 25
D. 27
Answer» D. 27
28.

What will be the value stored in max_value when the following code is executed?

A. 5
B. 6
C. 7
D. 8
Answer» D. 8
29.

What will be the output when the following code is executed?

A. 34
B. 55
C. Compile error
D. 21
Answer» E.
30.

What is the time complexity of Kadane s algorithm?

A. O(1)
B. O(n)
C. O(n^2)
D. None of the mentioned
Answer» C. O(n^2)
31.

Suppose we find the 8th term using the recursive implementation. The arguments passed to the function calls will be as follows:fibonacci(8)fibonacci(7) + fibonacci(6)fibonacci(6) + fibonacci(5) + fibonacci(5) + fibonacci(4)fibonacci(5) + fibonacci(4) + fibonacci(4) + fibonacci(3) + fibonacci(4) + fibonacci(3) + fibonacci(3) + fibonacci(2):::Which property is shown by the above function calls?

A. Memoization
B. Optimal substructure
C. Overlapping subproblems
D. Greedy
Answer» D. Greedy
32.

Suppose you are given infinite coins of N denominations v1, v2, v3, ..,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. What is the space complexity of a dynamic programming implementation used to solve the coin change problem?

A. O(N)
B. O(S)
C. O(N^2)
D. O(S*N)
Answer» C. O(N^2)
33.

Suppose you have coins of denominations 1,3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm produce an optimal answer?

A. 14
B. 10
C. 6
D. 100
Answer» E.
34.

The following sequence is a fibonacci sequence:0, 1, 1, 2, 3, 5, 8, 13, 21, ..Which technique can be used to get the nth fibonacci term?

A. Recursion
B. Dynamic programming
C. A single for loop
D. All of the mentioned
Answer» E.
35.

Find the maximum sub-array sum for the following array: {3, 6, 7, 9, 3, 8}

A. 33
B. 36
C. 23
D. 26
Answer» C. 23
36.

For which of the following inputs would Kadane s algorithm produce the CORRECT output?

A. {0,1,2,3}
B. {-1,0,1}
C. {-1,-2,-3,0}
D. All of the mentioned
Answer» E.
37.

Consider the following dynamic programming implementation of the edit distance problem. Which of the following lines should be added to complete the below code?

A. Arr[i-1][j] = min
B. Arr[i][j-1] = min
C. Arr[i-1][j-1] = min
D. Arr[i][j] = min
Answer» E.
38.

Consider the following dynamic programming implementation of the Knapsack problem.Which of the following lines completes the below code?

A. Find_max(ans[itm 1][w wt[itm 1]] + val[itm 1], ans[itm 1][w])
B. Find_max(ans[itm 1][w wt[itm 1]], ans[itm 1][w])
C. Ans[itm][w] = ans[itm 1][w],
D. None of the mentioned
Answer» B. Find_max(ans[itm 1][w wt[itm 1]], ans[itm 1][w])
39.

Consider the following dynamic programming implementation of the longest common subsequence problem.Which of the following lines completes the below code?

A. Arr[i][j] = 1 + arr[i][j].
B. Arr[i][j] = 1 + arr[i 1][j 1].
C. Arr[i][j] = arr[i 1][j 1].
D. Arr[i][j] = arr[i][j].
Answer» C. Arr[i][j] = arr[i 1][j 1].
40.

Consider the following dynamic programming implementation of the matrix chain problem.Which of the following lines should be inserted to complete the below code?

A. Arr[row][k] arr[k + 1][col] + mat[row 1] * mat[k] * mat[col],
B. Arr[row][k] + arr[k + 1][col] mat[row 1] * mat[k] * mat[col],
C. Arr[row][k] + arr[k + 1][col] + mat[row 1] * mat[k] * mat[col],
D. Arr[row][k] arr[k + 1][col] mat[row 1] * mat[k] * mat[col],
Answer» D. Arr[row][k] arr[k + 1][col] mat[row 1] * mat[k] * mat[col],
41.

Consider the following dynamic programming implementation of the minimum jumps problem.Which of the following for loops can be used instead of the inner for loop so that the output doesn t change?

A. For(j = 1, j < arr[idx] + len, j++)
B. For(j = 0, j < arr[idx] len, j++)
C. For(j = idx + 1, j < len && j <= arr[idx] + idx, j++)
D. None of the mentioned
Answer» E.
42.

Consider the following dynamic programming implementation of the rod cutting problem. Which line will complete the Below code?

A. Prices[j-1] + max_val[tmp_idx].
B. Prices[j] + max_val[tmp_idx].
C. Prices[j-1] + max_val[tmp_idx 1].
D. Prices[j] + max_val[tmp_idx 1].
Answer» B. Prices[j] + max_val[tmp_idx].
43.

Consider the following implementation of Kadane s algorithm.What changes should be made to the Kadane s algorithm so that it produces the right output even when all array elements are negative? Change 1 = Line 10: int sum = arr[0], ans = arr[0] Change 2 = Line 13: sum = max_num(arr[idx],sum+arr[idx])

A. Only Change 1 is sufficient
B. Only Change 2 is sufficient
C. Both Change 1 and Change 2 are necessary
D. None of the mentioned
Answer» D. None of the mentioned
44.

Consider the following implementation of the Wagner Fischer algorithm:Which of the following lines should be inserted to complete the below code?

A. Arr[i][j] = min
B. Min = arr[i-1][j-1] 1,
C. Min = arr[i-1][j-1].
D. Min = arr[i-1][j-1] + 1,
Answer» D. Min = arr[i-1][j-1] + 1,
45.

Consider the following naive method to find the maximum sub-array sum:Which line should be inserted to complete the below code?

A. Tmp_max = cur_max
B. Break
C. Continue
D. Cur_max = tmp_max
Answer» E.
46.

Consider the following recursive implementation of the rod cutting problem. Complete the below code.

A. Max_price, prices[i] + rod_cut(prices,len i 1)
B. Max_price, prices[i 1].
C. Max_price, rod_cut(prices, len i 1)
D. Max_price, prices[i 1] + rod_cut(prices,len i 1)
Answer» B. Max_price, prices[i 1].
47.

Consider the following recursive implementation.Which of these arguments should be passed by the min_jumps function represented by the blanks?

A. Arr, strt + idx, end
B. Arr + idx, strt, end
C. Arr, strt, end
D. Arr, strt, end + idx
Answer» B. Arr + idx, strt, end
48.

Consider the recursive implementation to find the nth fibonacci number:Which line would make the implementation complete?

A. Fibo(n) + fibo(n)
B. Fibo(n) + fibo(n 1)
C. Fibo(n 1) + fibo(n + 1)
D. Fibo(n 1) + fibo(n 2)
Answer» E.
49.

Consider the following assembly line problem.For the optimal solution, which should be the exit assembly line?

A. Line 1
B. Line 2
C. All of the mentioned
D. None of the mentioned
Answer» C. All of the mentioned
50.

Consider the following assembly line problem.What is the minimum time required to build the car chassis?

A. 40
B. 41
C. 42
D. 43
Answer» E.