Question: The following algorithm is a brute-force solution for a problem called MaxSubarraySum. It finds the contiguous subarray with the largest sum and returns that sum.

The following algorithm is a brute-force solution for a problem called MaxSubarraySum. It finds the contiguous subarray with the largest sum and returns that sum. For example: if the input array is [?6, ?1, 6, ?1, ?4, 1, 5, ?3] the algorithm would output 7.

func MaxSubArraySum(list)

maxSum <- -infinity

for i <- 0 ... list.size() - 1

runningSum <- 0

for j <- i ... list.size() - 1

runningSum <- runningSum + list[j]

if runningSum > maxSum

maxSum <- runningSum

return maxSum

(a) What parameter should be used to measure the size of the input?

(b) Give a summation that represents the number additions that are performed.

(c) Find a closed form for your summation and give its order of growth.

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!