Question: Revise the following algorithm to find the minimum contiguous subsequence sum and return it along with the indices: def maxSumRec(a, left, right): if left ==

Revise the following algorithm to find the minimum contiguous subsequence sum and return it along with the indices:

def maxSumRec(a, left, right):

if left == right:

if a[left] > 0:

return a[left]

else:

return 0

center = int((left + right) / 2)

maxLeftSum = maxSumRec(a, left, center)

maxRightSum = maxSumRec(a, center + 1, right)

maxLeftBorderSum, leftBorderSum = 0, 0

for i in range(center, left, -1):

leftBorderSum += a[i]

if leftBorderSum > maxLeftBorderSum:

maxLeftBorderSum = leftBorderSum

maxRightBorderSum, rightBorderSum = 0, 0

for i in range(center + 1, right + 1):

rightBorderSum += a[i]

if rightBorderSum > maxRightBorderSum:

maxRightBorderSum = rightBorderSum

return max(maxLeftSum, maxRightSum, maxLeftBorderSum + maxRightBorderSum)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!