1.

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.



Discussion

No Comment Found

Related InterviewSolutions