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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started