Explore topic-wise InterviewSolutions in .

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

51.

Wagner–Fischer is a ____________ algorithm.(a) Brute force(b) Greedy(c) Dynamic programming(d) RecursiveThis question was addressed to me in an interview for internship.This is a very interesting question from Wagner-Fischer Algorithm in division Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT OPTION is (c) DYNAMIC programming

The best explanation: Wagner–Fischer BELONGS to the dynamic programming TYPE of algorithms.
52.

Consider the two strings “”(empty string) and “abcd”. What is the edit distance between the two strings?(a) 0(b) 4(c) 2(d) 3I got this question in an interview.I'm obligated to ask this question of Edit Distance Problem in division Dynamic Programming of Data Structures & Algorithms II

Answer»

Right option is (B) 4

Easiest 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.

53.

Consider the strings “monday” and “tuesday”. What is the edit distance between the two strings?(a) 3(b) 4(c) 5(d) 6This question was addressed to me in unit test.My question is taken from Edit Distance Problem in portion Dynamic Programming of Data Structures & Algorithms II

Answer»

The correct ANSWER is (B) 4

The best 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.

54.

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) FalseThe question was asked during a job interview.My enquiry is from Edit Distance Problem topic in portion Dynamic Programming of Data Structures & Algorithms II

Answer» RIGHT option is (a) True

The explanation is: 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.
55.

In which of the following cases will the edit distance between two strings be zero?(a) When one string is a substring of another(b) When the lengths of the two strings are equal(c) When the two strings are equal(d) The edit distance can never be zeroThe question was posed to me in examination.Asked question is from Edit Distance Problem topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct OPTION is (c) When the two STRINGS are equal

For EXPLANATION: The EDIT distance will be zero only when the two strings are equal.

56.

Which of the following is an application of the edit distance problem?(a) Approximate string matching(b) Spelling correction(c) Similarity of DNA(d) Approximate string matching, Spelling Correction and Similarity of DNAThis question was posed to me in an online quiz.I need to ask this question from Edit Distance Problem in division Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT option is (d) Approximate string MATCHING, Spelling CORRECTION and Similarity of DNA

To EXPLAIN: All of the mentioned are the applications of the EDIT distance problem.
57.

Which of the following is an application of the edit distance problem?(a) Approximate string matching(b) Spelling correction(c) Similarity of DNA(d) Approximate string matching, Spelling Correction and Similarity of DNAThis question was addressed to me in my homework.My question is taken from Edit Distance Problem topic in section Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT choice is (d) APPROXIMATE string matching, Spelling Correction and Similarity of DNA

All of the MENTIONED are the APPLICATIONS of the edit distance problem.

58.

The edit distance satisfies the axioms of a metric when the costs are non-negative.(a) True(b) FalseThis question was addressed to me in unit test.Asked question is from Edit Distance Problem topic in division Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT option is (a) True

Easiest 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.

d(s1, s2) = d(s2, s1)

d(s1, s3) <= d(s1, s2) + d(s2, s3)

Thus, the edit DISTANCE satisfies the axioms of a METRIC.
59.

Which of the following methods can be used to solve the edit distance problem?(a) Recursion(b) Dynamic programming(c) Both dynamic programming and recursion(d) Greedy AlgorithmThis question was addressed to me during a job interview.The origin of the question is Edit Distance Problem topic in portion Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT CHOICE is (c) Both dynamic programming and recursion

Best explanation: Both dynamic programming and recursion can be USED to solve the edit DISTANCE problem.

60.

Longest palindromic subsequence is an example of ______________(a) Greedy algorithm(b) 2D dynamic programming(c) 1D dynamic programming(d) Divide and conquerI got this question in an internship interview.This interesting question is from Longest Palindromic Subsequence topic in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct option is (B) 2D dynamic PROGRAMMING

For EXPLANATION: Longest PALINDROMIC SUBSEQUENCE is an example of 2D dynamic programming.

61.

For every non-empty string, the length of the longest palindromic subsequence is at least one.(a) True(b) FalseI got this question in an international level competition.My doubt is from Longest Palindromic Subsequence topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct ANSWER is (a) True

The explanation is: A single CHARACTER of any string can ALWAYS be considered as a palindrome and its length is ONE.

62.

What is the time complexity of the brute force algorithm used to find the length of the longest palindromic subsequence?(a) O(1)(b) O(2^n)(c) O(n)(d) O(n^2)The question was posed to me in semester exam.The origin of the question is Longest Palindromic Subsequence in division Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct option is (b) O(2^n)

The BEST I can explain: In the BRUTE force ALGORITHM, all the subsequences are found and the length of the longest palindromic subsequence is calculated. This takes exponential TIME.

63.

What is the length of the longest palindromic subsequence for the string “ababcdabba”?(a) 6(b) 7(c) 8(d) 9I have been asked this question in unit test.Origin of the question is Longest Palindromic Subsequence topic in section Dynamic Programming of Data Structures & Algorithms II

Answer» RIGHT answer is (b) 7

To EXPLAIN: The LONGEST palindromic SUBSEQUENCE is “abbabba” and its length is 7.
64.

For which of the following, the length of the string is not equal to the length of the longest palindromic subsequence?(a) A string that is a palindrome(b) A string of length one(c) A string that has all the same letters(e.g. aaaaaa)(d) Some strings of length twoThis question was addressed to me in an international level competition.This is a very interesting question from Longest Palindromic Subsequence topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT choice is (d) Some strings of length two

The explanation is: A STRING of length 2 for EG: ab is not a PALINDROME.

65.

Which of the following is not a palindromic subsequence of the string “ababcdabba”?(a) abcba(b) abba(c) abbbba(d) adbaThe question was asked during an interview for a job.I need to ask this question from Longest Palindromic Subsequence topic in division Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT OPTION is (d) adba

The best I can explain: ‘adba’ is not a palindromic SEQUENCE.
66.

Which of the following methods can be used to solve the longest palindromic subsequence problem?(a) Dynamic programming(b) Recursion(c) Brute force(d) Dynamic programming, Recursion, Brute forceI got this question by my college director while I was bunking the class.I want to ask this question from Longest Palindromic Subsequence topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Right option is (d) Dynamic programming, Recursion, Brute FORCE

Best explanation: Dynamic programming, Recursion, Brute force can be USED to solve the longest PALINDROMIC subsequence PROBLEM.

67.

Which of the following is the longest common subsequence between the strings “hbcfgmnapq” and “cbhgrsfnmq” ?(a) hgmq(b) cfnq(c) bfmq(d) fgmnaI have been asked this question during an online exam.This interesting question is from Longest Common Subsequence in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Right option is (d) fgmna

Easy explanation - The LENGTH of the longest COMMON SUBSEQUENCE is 4. But ‘fgmna’ is not the longest common subsequence as its length is 5.

68.

What is the time complexity of the brute force algorithm used to find the longest common subsequence?(a) O(n)(b) O(n^2)(c) O(n^3)(d) O(2^n)This question was addressed to me in an interview for internship.My question is based upon Longest Common Subsequence topic in section Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT answer is (d) O(2^n)

EASIEST explanation - The TIME COMPLEXITY of the BRUTE force algorithm used to find the longest common subsequence is O(2^n).
69.

Longest common subsequence is an example of ____________(a) Greedy algorithm(b) 2D dynamic programming(c) 1D dynamic programming(d) Divide and conquerI have been asked this question by my college director while I was bunking the class.My question is from Longest Common Subsequence topic in portion Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT answer is (B) 2D dynamic programming

The BEST I can explain: LONGEST common subsequence is an EXAMPLE of 2D dynamic programming.
70.

Which of the following problems can be solved using the longest subsequence problem?(a) Longest increasing subsequence(b) Longest palindromic subsequence(c) Longest bitonic subsequence(d) Longest decreasing subsequenceI got this question in examination.I would like to ask this question from Longest Common Subsequence topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT option is (b) Longest palindromic SUBSEQUENCE

The best explanation: To find the longest palindromic subsequence in a given string, reverse the given string and then find the longest COMMON subsequence in the given string and the REVERSED string.
71.

Consider the strings “PQRSTPQRS” and “PRATPBRQRPS”. What is the length of the longest common subsequence?(a) 9(b) 8(c) 7(d) 6This question was addressed to me in quiz.My doubt stems from Longest Common Subsequence in section Dynamic Programming of Data Structures & Algorithms II

Answer»

The correct option is (C) 7

For EXPLANATION: The LONGEST common subsequence is “PRTPQRS” and its LENGTH is 7.

72.

Which of the following methods can be used to solve the longest common subsequence problem?(a) Recursion(b) Dynamic programming(c) Both recursion and dynamic programming(d) Greedy algorithmThe question was asked in an online quiz.Origin of the question is Longest Common Subsequence topic in portion Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT option is (c) Both recursion and dynamic programming

For EXPLANATION: Both recursion and dynamic programming can be used to SOLVE the longest SUBSEQUENCE PROBLEM.

73.

Consider the brute force implementation in which we find all the possible ways of multiplying the given set of n matrices. What is the time complexity of this implementation?(a) O(n!)(b) O(n^3)(c) O(n^2)(d) ExponentialThis question was posed to me in unit test.This interesting question is from Matrix-chain Multiplication topic in portion Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT option is (d) Exponential

Easy explanation - The time COMPLEXITY of finding all the possible WAYS of multiplying a set of n MATRICES is given by (n-1)^th Catalan NUMBER which is exponential.

74.

Consider the matrices P, Q, R and S which are 20 x 15, 15 x 30, 30 x 5 and 5 x 40 matrices respectively. What is the minimum number of multiplications required to multiply the four matrices?(a) 6050(b) 7500(c) 7750(d) 12000I had been asked this question in semester exam.My question comes from Matrix-chain Multiplication in division Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT ANSWER is (c) 7750

Best EXPLANATION: The minimum number of multiplications REQUIRED is 7750.
75.

Consider the matrices P, Q and R which are 10 x 20, 20 x 30 and 30 x 40 matrices respectively. What is the minimum number of multiplications required to multiply the three matrices?(a) 18000(b) 12000(c) 24000(d) 32000This question was addressed to me in final exam.This is a very interesting question from Matrix-chain Multiplication topic in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Right answer is (a) 18000

Easy EXPLANATION - The MINIMUM number of multiplications are 18000. This is the case when the MATRICES are PARENTHESIZED as (P*Q)*R.

76.

Consider the two matrices P and Q which are 10 x 20 and 20 x 30 matrices respectively. What is the number of multiplications required to multiply the two matrices?(a) 10*20(b) 20*30(c) 10*30(d) 10*20*30I have been asked this question during an interview for a job.Enquiry is from Matrix-chain Multiplication in portion Dynamic Programming of Data Structures & Algorithms II

Answer» RIGHT answer is (d) 10*20*30

The BEST EXPLANATION: The NUMBER of multiplications required is 10*20*30.
77.

Which of the following methods can be used to solve the matrix chain multiplication problem?(a) Dynamic programming(b) Brute force(c) Recursion(d) Dynamic Programming, Brute force, RecursionI got this question by my college director while I was bunking the class.This question is from Matrix-chain Multiplication in section Dynamic Programming of Data Structures & Algorithms II

Answer» RIGHT CHOICE is (d) DYNAMIC Programming, BRUTE force, Recursion

Easy explanation - Dynamic Programming, Brute force, Recursion methods can be used to solve the matrix chain MULTIPLICATION problem.
78.

The 0-1 Knapsack problem can be solved using Greedy algorithm.(a) True(b) FalseThe question was asked during an interview for a job.My question is from 0/1 Knapsack Problem topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Right answer is (B) False

For EXPLANATION: The KNAPSACK problem cannot be solved using the greedy ALGORITHM.

79.

What is the time complexity of the brute force algorithm used to solve the Knapsack problem?(a) O(n)(b) O(n!)(c) O(2^n)(d) O(n^3)I had been asked this question in an interview for internship.My question is taken from 0/1 Knapsack Problem in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Right option is (c) O(2^n)

The BEST explanation: In the brute FORCE algorithm all the subsets of the items are found and the value of each subset is CALCULATED. The subset of items with the maximum value and a weight less than EQUAL to the maximum allowed weight gives the answer. The time taken to calculate all the subsets is O(2^n).

80.

Which of the following problems is equivalent to the 0-1 Knapsack problem?(a) You are given a bag that can carry a maximum weight of W. You are given N items which have a weight of {w1, w2, w3,…., wn} and a value of {v1, v2, v3,…., vn}. You can break the items into smaller pieces. Choose the items in such a way that you get the maximum value(b) You are studying for an exam and you have to study N questions. The questions take {t1, t2, t3,…., tn} time(in hours) and carry {m1, m2, m3,…., mn} marks. You can study for a maximum of T hours. You can either study a question or leave it. Choose the questions in such a way that your score is maximized(c) You are given infinite coins of denominations {v1, v2, v3,….., vn} and a sum S. You have to find the minimum number of coins required to get the sum S(d) You are given a suitcase that can carry a maximum weight of 15kg. You are given 4 items which have a weight of {10, 20, 15,40} and a value of {1, 2, 3,4}. You can break the items into smaller pieces. Choose the items in such a way that you get the maximum valueI got this question at a job interview.My question is from 0/1 Knapsack Problem in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Right option is (b) You are STUDYING for an exam and you have to study N questions. The questions take {t1, t2, t3,…., tn} time(in hours) and carry {m1, m2, m3,…., mn} marks. You can study for a MAXIMUM of T hours. You can either study a question or leave it. Choose the questions in such a way that your score is maximized

The best explanation: In this CASE, questions are used instead of ITEMS. Each question has a score which is same as each item having a value. Also, each question takes a time t which is same as each item having a weight W. You have to maximize the score in time T which is same as maximizing the value using a bag of weight W.

81.

You are given a knapsack that can carry a maximum weight of 60. There are 4 items with weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the maximum value of the items you can carry using the knapsack?(a) 160(b) 200(c) 170(d) 90This question was posed to me in an international level competition.Query is from 0/1 Knapsack Problem topic in division Dynamic Programming of Data Structures & Algorithms II

Answer» RIGHT answer is (a) 160

Explanation: The maximum VALUE you can get is 160. This can be achieved by CHOOSING the items 1 and 3 that have a total weight of 60.
82.

Which of the following methods can be used to solve the Knapsack problem?(a) Brute force algorithm(b) Recursion(c) Dynamic programming(d) Brute force, Recursion and Dynamic ProgrammingThis question was posed to me during an online interview.I need to ask this question from 0/1 Knapsack Problem in portion Dynamic Programming of Data Structures & Algorithms II

Answer»

The correct choice is (d) Brute force, Recursion and DYNAMIC Programming

Easy explanation - Brute force, Recursion and Dynamic Programming can be used to SOLVE the knapsack PROBLEM.

83.

The Knapsack problem is an example of ____________(a) Greedy algorithm(b) 2D dynamic programming(c) 1D dynamic programming(d) Divide and conquerThis question was addressed to me in class test.Question is taken from 0/1 Knapsack Problem in chapter Dynamic Programming of Data Structures & Algorithms II

Answer» CORRECT option is (B) 2D dynamic programming

The explanation is: KNAPSACK problem is an example of 2D dynamic programming.
84.

For any array, given that at most one element is non-zero, it is ALWAYS possible to reach the end of the array using minimum jumps.(a) True(b) FalseThe question was asked in semester exam.This question is from Minimum Number of Jumps topic in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct ANSWER is (B) False

Easy explanation - CONSIDER the array {1,0,2,3,4}.

In this case, only ONE element is 0 but it is not possible to REACH the end of the array.

85.

For a given array, there can be multiple ways to reach the end of the array using minimum number of jumps.(a) True(b) FalseThe question was posed to me in an online interview.My enquiry is from Minimum Number of Jumps topic in division Dynamic Programming of Data Structures & Algorithms II

Answer»

Right answer is (a) True

Easy explanation - CONSIDER the array {1,2,3,4,5}. It is possible to REACH the end in the following ways: {1 -> 2 -> 3 -> 5} or {1 -> 2 -> 4 -> 5}.

In both the cases the NUMBER of jumps is 3, which is minimum. Hence, it is possible to reach the end of the array in MULTIPLE ways using minimum number of jumps.

86.

You are given an array of elements where each array element represents the MAXIMUM number of jumps that can be made in the forward direction from that element. You have to find the minimum number of jumps that are required to reach the end of the array. Which of these methods can be used to solve the problem?(a) Dynamic Programming(b) Greedy Algorithm(c) Recursion(d) Recursion and Dynamic ProgrammingThis question was addressed to me in a national level competition.The above asked question is from Minimum Number of Jumps in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct choice is (d) RECURSION and Dynamic PROGRAMMING

Easy explanation - Both recursion and dynamic programming can be used to SOLVE MINIMUM number of jumps problem.

87.

For every rod cutting problem there will be a unique set of pieces that give the maximum price.(a) True(b) FalseI have been asked this question during an online exam.The doubt is from Rod Cutting in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Right CHOICE is (B) False

For explanation: Consider a rod of length 3. The PRICES are {2,3,6} for lengths {1,2,3} respectively. The pieces {1,1,1} and {3} both give the maximum value of 6.

88.

Consider the brute force implementation of the rod cutting problem in which all the possible cuts are found and the maximum value is calculated. What is the time complexity of this brute force implementation?(a) O(n^2)(b) O(n^3)(c) O(nlogn)(d) O(2^n)This question was addressed to me during an internship interview.This is a very interesting question from Rod Cutting topic in division Dynamic Programming of Data Structures & Algorithms II

Answer»

Right choice is (d) O(2^n)

The explanation is: The BRUTE force IMPLEMENTATION FINDS all the possible cuts. This takes O(2^n) TIME.

89.

Given a rod of length n and the selling prices of all pieces smaller than equal to n, find the most beneficial way of cutting the rod into smaller pieces. This problem is called the rod cutting problem. Which of these methods can be used to solve the rod cutting problem?(a) Brute force(b) Dynamic programming(c) Recursion(d) Brute force, Dynamic programming and RecursionThis question was posed to me in unit test.I would like to ask this question from Rod Cutting topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct OPTION is (d) Brute force, Dynamic programming and RECURSION

To explain: Brute force, Dynamic programming and Recursion can be used to SOLVE the rod cutting PROBLEM.

90.

In the brute force implementation to find the longest increasing subsequence, all the subsequences of a given sequence are found. All the increasing subsequences are then selected and the length of the longest subsequence is found. What is the time complexity of this brute force implementation?(a) O(n)(b) O(n^2)(c) O(n!)(d) O(2^n)This question was posed to me in semester exam.My question comes from Longest Increasing Subsequence in division Dynamic Programming of Data Structures & Algorithms II

Answer»

The correct option is (d) O(2^N)

For EXPLANATION: The time REQUIRED to find all the SUBSEQUENCES of a given sequence is 2^n, where ‘n’ is the NUMBER of elements in the sequence. So, the time complexity is O(2^n).

91.

For any given sequence, there will ALWAYS be a unique increasing subsequence with the longest length.(a) True(b) FalseI have been asked this question in a job interview.The question is from Longest Increasing Subsequence in portion Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct option is (b) False

To explain: For a GIVEN SEQUENCE, it is POSSIBLE that there is more than one subsequence with the longest length.

Consider, the following sequence: {10,11,12,1,2,3}:

There are two longest increasing subsequences: {1,2,3} and {10,11,12}.

92.

The longest increasing subsequence problem is a problem to find the length of a subsequence from a sequence of array elements such that the subsequence is sorted in increasing order and it’s length is maximum. This problem can be solved using __________(a) Recursion(b) Dynamic programming(c) Brute force(d) Recursion, Dynamic programming, Brute forceThe question was asked in an international level competition.My doubt stems from Longest Increasing Subsequence in portion Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT choice is (d) Recursion, Dynamic PROGRAMMING, Brute force

The best explanation: The LONGEST increasing subsequence PROBLEM can be solved using all of the mentioned methods.

93.

What is the time complexity of Kadane’s algorithm?(a) O(1)(b) O(n)(c) O(n^2)(d) O(5)The question was asked by my school teacher while I was bunking the class.My question is taken from Kadane’s Algorithm in division Dynamic Programming of Data Structures & Algorithms II

Answer»

Right option is (b) O(n)

EASY explanation - The TIME complexity of Kadane’s algorithm is O(n) because there is only ONE for loop which scans the entire ARRAY EXACTLY once.

94.

For which of the following inputs would Kadane’s algorithm produce a WRONG output?(a) {1,0,-1}(b) {-1,-2,-3}(c) {1,2,3}(d) {0,0,0}The question was asked in a job interview.This question is from Kadane’s Algorithm topic in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct option is (b) {-1,-2,-3}

The best I can explain: KADANE’s algorithm doesn’t work for all NEGATIVE NUMBERS. So, the ANSWER is {-1,-2,-3}.

95.

For which of the following inputs would Kadane’s algorithm produce the INCORRECT output?(a) {0,1,2,3}(b) {-1,0,1}(c) {-1,-2,-3,0}(d) {-4,-3,-2,-1}The question was posed to me in an international level competition.My query is from Kadane’s Algorithm in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct CHOICE is (d) {-4,-3,-2,-1}

The best I can explain: Kadane’s algorithm works if the INPUT array contains at least ONE non-negative ELEMENT. Every element in the array {-4,-3,-2,-1} is negative. Hence Kadane’s algorithm won’t work.

96.

Kadane’s algorithm uses which of the following techniques?(a) Divide and conquer(b) Dynamic programming(c) Recursion(d) Greedy algorithmI got this question in semester exam.I'm obligated to ask this question of Kadane’s Algorithm topic in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Right choice is (b) Dynamic PROGRAMMING

To explain: Kadane’s ALGORITHM USES dynamic programming.

97.

Kadane’s algorithm is used to find ____________(a) Longest increasing subsequence(b) Longest palindrome subsequence(c) Maximum sub-array sum(d) Longest decreasing subsequenceThis question was addressed to me in quiz.I would like to ask this question from Kadane’s Algorithm topic in division Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT choice is (C) MAXIMUM sub-array sum

For explanation: Kadane’s ALGORITHM is used to find the maximum sub-array sum for a GIVEN array.

98.

What is the space complexity of the divide and conquer algorithm used to find the maximum sub-array sum?(a) O(n)(b) O(1)(c) O(n!)(d) O(n^2)This question was addressed to me in my homework.My query is from Maximum Sum of Continuous Subarray topic in section Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT OPTION is (b) O(1)

The best explanation: The DIVIDE and conquer algorithm USES a constant SPACE. So, the space complexity is O(1).

99.

What is the time complexity of the divide and conquer algorithm used to find the maximum sub-array sum?(a) O(n)(b) O(logn)(c) O(nlogn)(d) O(n^2)The question was posed to me by my school principal while I was bunking the class.The question is from Maximum Sum of Continuous Subarray topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Right CHOICE is (C) O(nlogn)

Best explanation: The TIME complexity of the divide and CONQUER algorithm used to find the MAXIMUM sub-array sum is O(nlogn).

100.

Given a one-dimensional array of integers, you have to find a sub-array with maximum sum. This is the maximum sub-array sum problem. Which of these methods can be used to solve the problem?(a) Dynamic programming(b) Two for loops (naive method)(c) Divide and conquer(d) Dynamic programming, naïve method and Divide and conquer methodsI have been asked this question in an internship interview.Question is taken from Maximum Sum of Continuous Subarray in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Right choice is (d) Dynamic programming, naïve METHOD and Divide and conquer methods

The BEST explanation: Dynamic programming, naïve method and Divide and conquer methods can be used to solve the maximum SUB ARRAY sum problem.