Design and Analysis of Algorithms Solved MCQs (Set-11)
Design and Analysis of Algorithms Solved MCQs (Set-11)
[set-11]
m
252. Which of the following methods can be used to solve the edit distance
o
problem?
. c
A. recursion
te
B. dynamic programming
a
M
C. both dynamic programming and recursion
q
D. greedy algorithm
Answer: C c
M
Explanation:- both dynamic programming and recursion can be used to solve the edit distance
problem.
253. The edit distance satisfies the axioms of a metric when the costs are non-
negative.
A. true
B. false
Answer: A
Explanation:- d(s,s) = 0, since each string can be transformed into itself without any change. d(s1,
s2) > 0 when s1 != s2, since the transformation would require at least one operation.
254. Suppose each edit (insert, delete, replace) has a cost of one. Then, the
maximum edit distance cost between the two strings is equal to the length of the
larger string.
A. true
B. false
Answer: A
Explanation:- consider the strings “abcd” and “efghi”. the string “efghi” can be converted to “abcd” by
deleting “i” and converting “efgh” to “abcd”. the cost of transformation is 5, which is equal to the
length of the larger string.
255. Consider the strings “monday” and “tuesday”. What is the edit distance
between the two strings?
A. 3
B. 4
C. 5
D. 6
Answer: B
Explanation:- “monday” can be converted to “tuesday” by replacing “m” with “t”, “o” with “u”, “n” with
“e” and inserting “s” at the appropriate position. so, the edit distance is 4.
256. Consider the two strings “”(empty string) and “abcd”. What is the edit
distance between the two strings?
A. 0
B. 4
C. 2
D. 3
Answer: B
Explanation:- the empty string can be transformed into “abcd” by inserting “a”, “b”, “c” and “d” at
appropriate positions. thus, the edit distance is 4.
257. 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: C
Explanation:- the time complexity of the wagner–fischer algorithm is o(mn).
259. Which of the following methods can be used to find the nth Catalan number?
A. recursion
B. binomial coefficients
C. dynamic programming
D. recursion, binomial coefficients, dynamic programming
Answer: D
Explanation:- all of the mentioned methods can be used to find the nth catalan number.
260. Which of the following implementations of Catalan numbers has the smallest
time complexity?
A. dynamic programming
B. binomial coefficients
C. recursion
D. all have equal time complexity
Answer: B
Explanation:- The time complexities are as follows: Dynamic programming: O(n2) Recursion:
Exponential Binomial coefficients: O(n).
261. Which of the following methods can be used to solve the assembly line
scheduling problem?
A. recursion
B. brute force
C. dynamic programming
D. all of the mentioned
Answer: D
Explanation:- all of the above mentioned methods can be used to solve the assembly line
scheduling problem.
262. What is the time complexity of the brute force algorithm used to solve the
assembly line scheduling problem?
A. o(1)
B. o(n)
265. Given a string, you have to find the minimum number of characters to be
inserted in the string so that the string becomes a palindrome. Which of the
following methods can be used to solve the problem?
A. greedy algorithm
B. recursion
C. dynamic programming
D. both recursion and dynamic programming
Answer: D
Explanation:- dynamic programming and recursion can be used to solve the problem.
267. In the worst case, the minimum number of insertions to be made to convert
the string into a palindrome is equal to the length of the string.
A. true
B. false
C. answer: b
D. explanation: in the worst case, the minimum number of insertions to be made to convert the
string into a palindrome is equal to length of the string minus one. for example, consider the string
“abc”. the string can be converted to “abcba” by inserting “a” and “b”. the number of insertions is
two, which is equal to length minus one.
Answer: B
Explanation:- the string can be converted to “efgfe” by inserting “f” or to “egfge” by inserting “g”.
thus, only one insertion is required.
268. Consider the string “abbccbba”. What is the minimum number of insertions
required to make the string a palindrome?
A. 0
B. 1
C. 2
D. 3
Answer: A
Explanation:- the given string is already a palindrome. so, no insertions are required.
270. Given a 2D matrix, find a submatrix that has the maximum sum. Which of the
following methods can be used to solve this problem?
A. brute force
B. recursion
C. dynamic programming
D. brute force, recursion, dynamic programming
Answer: D
Explanation:- brute force, recursion and dynamic programming can be used to find the submatrix
that has the maximum sum.
271. In which of the following cases, the maximum sum rectangle is the 2D matrix
itself?
A. when all the elements are negative
B. when all the elements are positive
C. when some elements are positive and some negative
D. when diagonal elements are positive and rest are negative
Answer: A
Explanation:- when all the elements of a matrix are positive, the maximum sum rectangle is the 2d
matrix itself.
272. Consider the 2×3 matrix {{1,2,3},{1,2,3}}. What is the sum of elements of the
maximum sum rectangle?
A. 3
B. 6
C. 12
D. 18
Answer: C
273. Consider the 2×2 matrix {{-1,-2},{-3,-4}}. What is the sum of elements of the
maximum sum rectangle?
A. 0
B. -1
C. -7
D. -12
Answer: B
Explanation:- since all the elements of the 2×2 matrix are negative, the maximum sum rectangle is {-
1}, a 1×1 matrix containing the largest element. the sum of elements of the maximum sum rectangle
is -1.
275. 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. dynamic programming, recursion, brute force
Answer: D
Explanation:- all of the mentioned methods can be used to solve the balanced partition