Data Structure Questions and Answers-Kadane’s Algorithm

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

Data Structure Questions and Answers-Kadane's Algorithm

Click on any option to know the CORRECT ANSWERS

Question 1
Kadane's algorithm is used to find .....
A
Longest increasing subsequence
B
Longest palindrome subsequence
C
Maximum sub-array sum
D
All of the mentioned
Visual arts Questions answers

Question 1 Explanation: 
Kadane's algorithm is used to find the maximum sub-array sum for a given array.

Question 2
Kadane's algorithm uses which of the following techniques?
A
Divide and conquer
B
Dynamic programming
C
Recursion
D
All of the mentioned
Bank exam Questions answers

Question 2 Explanation: 
Kadane's algorithm uses dynamic programming.

Question 3
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
Bank exam Questions answers

Question 3 Explanation: 
Kadane's algorithm works if the input array contains at least one non-negative element. All the array inputs have at least one non-negative element. So, Kadane's algorithm will produce the right output for all of the mentioned inputs.

Question 4
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}
UPSC test Questions answers

Question 4 Explanation: 
Kadane's algorithm doesn't work for all negative numbers. So, the answer is {-1, -2, -3}.

Question 5
Complete the following code for Kadane's algorithm:

#include<stdio.h> int max....num(int a, int b) { if(a > b) return a; return b; } int kadane....algo(int *arr, int len) {	 int ans, sum, idx; ans =0; sum =0; for(idx =0; idx < len; idx++) { sum = max....num(0, sum + arr[idx]); ans = .....; } return ans; } int main() { int arr[] = {-2, -3, 4, -1, -2, 1, 5, -3}, len=7; int ans = kadane....algo(arr, len); printf("%d", ans); return 0; }
A
max....num(sum, sum + arr[idx])
B
sum
C
sum + arr[idx].
D
max....num(sum, ans)
EVS Questions answers

Question 5 Explanation: 
The maximum of sum and ans, is stored in ans. So, the answer is max....num(sum, ans).

There are 5 questions to complete.

 

 Download all FREE PDF Ebook >>>CLICK HERE<<<