Explore topic-wise MCQs in Data Structures and Algorithms.

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

1.

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

A. 0
B. 1
C. -1
D. -2View Answer
Answer» C. -1
2.

What is the space complexity of the following dynamic programming implementation of the balanced partition problem?

A. O(sum)
B. O(n)
C. O(sum * n)
D. O(sum + n)View Answer
Answer» D. O(sum + n)View Answer
3.

What is the time complexity of the following dynamic programming implementation of the balanced partition problem where “n” is the number of elements and “sum” is their sum?

A. O(sum)
B. O(n)
C. O(sum * n)
D. O(sum + n)View Answer
Answer» D. O(sum + n)View Answer
4.

Consider a variation of the balanced partition problem in which we find two subsets such that |S1 – S2| is minimum. Consider the array {1, 2, 3, 4, 5}. Which of the following pairs of subsets is an optimal solution for the above problem?

A. {5, 4} & {3, 2, 1}
B. {5} & {4, 3, 2, 1}
C. {4, 2} & {5, 3, 1}
D. {5, 3} & {4, 2, 1}
Answer» E.
5.

What is the space complexity of the above dynamic programming implementation of the balanced partition problem?

A. O(sum)
B. O(n)
C. O(sum * n)
D. O(sum + n)
Answer» B. O(n)
6.

What is the time complexity of the above dynamic programming implementation of the balanced partition problem where “n” is the number of elements and “sum” is their sum?$

A. O(sum)
B. O(n)
C. O(sum * n)
D. O(sum + n)
Answer» D. O(sum + n)
7.

Consider a variation of the balanced partition problem in which we find two subsets such that |S1 – S2| is minimum. Consider the array {1, 2, 3, 4, 5}. Which of the following pairs of subsets is an optimal solution for the above problem?$

A. {5, 4} & {3, 2, 1}
B. {5} & {4, 3, 2, 1}
C. {4, 2} & {5, 3, 1}
D. {5, 3} & {4, 2, 1}
Answer» E.
8.

What is the time complexity of the brute force algorithm used to solve the balanced partition problem?

A. O(1)
B. O(n)
C. O(n<sup>2</sup>)
D. O(2<sup>n</sup>)
Answer» E.
9.

In which of the following cases, it is not possible to have two subsets with equal sum?

A. When the number of elements is odd
B. When the number of elements is even
C. When the sum of elements is odd
D. When the sum of elements is even
Answer» D. When the sum of elements is even
10.

Given an array, check if the array can be divided into two subsets such that the sum of elements of the two subsets is equal. This is the balanced partition problem. Which of the following methods can be used to solve the balanced partition problem?

A. Dynamic programming
B. Recursion
C. Brute force
D. All of the mentioned
Answer» E.