in Algorithms
5,368 views
3 votes
3 votes

Maximum Subarray Sum problem is to find the subarray with maximum sum. For example, given an array {12, -13, -5, 25, -20, 30, 10}, the maximum subarray sum is 45. The naive solution for this problem is to calculate sum of all subarrays starting with every element and return the maximum of all. We can solve this using Divide and Conquer, what will be the worst case time complexity using Divide and Conquer.

A

O(n)

B

O(nLogn)

C

O(Logn)

D O(n2)

Correct answer is B. O(nLogn) How? 

in Algorithms
5.4k views

3 Comments

I think that the answer needs to be O(n), We  can use dynamic programming to solve it. 

Please refer : https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/ 

0
0

Have you gone through this algo? https://www.geeksforgeeks.org/divide-and-conquer-maximum-sum-subarray/

Sumit Singh Chauhan The question is asking about the Divide and Conquer implementation

1
1

Oh Yes, thanks for noticing the answer will be O(nlogn) using divide and conquer. O(n) is possible only via Dynamic Programming using Kadane’s Algorithm.

0
0

Please log in or register to answer this question.