Question: Let A be an array of integers ( some integers can be negative ) . Assume that the array is of size n . The
Let A be an array of integers some integers can be negative Assume that the array is of size n The subarray Aij
is the part of the array that starts at index i and ends at index j where i j n Let sij equal the sum of the
integers in Aij
We wish to solve the following problem:
Find the maximum value for sij over all subarrays in array A where i j n
The three algorithms given below solve this problem. NOTE: If all of the values in the array are negative, then the
maximum value for sij is by default.
Example: If the array contains the values then the maximum sum over all subarrays is for
the subarray If the array contains the values then the maximum sum over all
subarrays is for the subarray
ALGORITHM
Start with a maximum sum of Compute the sum of each element subarray, then compute the sum of each
element subarray, then compute the sum of each element subarray, etc. For each sum you compute, if it is larger
than the maximum sum you've seen, then it becomes the maximum sum.
ALGORITHM
Start with a maximum sum of Compute the sum of each subarray that starts at index then compute the sum of
each subarray that starts at index then compute the sum of each subarray that starts at index etc. For each sum
you compute, if it is larger than the maximum sum you've seen, then it becomes the maximum sum.
EFFICIENCY NOTE: Once you compute the sum of the subarray from Ai to Aj the sum of the subarray from Ai
to Aj is just the previous sum you computed plus Aj Don't add up all of the previous values all over again.
ALGORITHM
Start with a maximum sum of Compute the sum of all subarrays starting from index Use the efficiency note from
Algorithm If the sum you compute is negative, start computing the sum of all subarrays starting from the next index
in the array. Repeat this special rule if necessary. For each sum you compute, if it is larger than the maximum sum
you've seen, then it becomes the maximum sum.
For example, as you compute the sum of all subarrays starting from index if you find the sum of the integers in
A is negative, then compute the sum of all subarrays starting from index next. If the sum of the integers from
A is negative, then compute the sum of all subarrays starting from index Etc.
You are to write a c program that determines the amount of work each of these algorithms does to compute its
answer for arrays of various sizes. Using this data, you are to determine the runtime complexity of each algorithm.
Write a class MethodTester that contains a main method and three helper methods, one to implement each
algorithm above. Your main method should test your methods with small arrays like the ones in the
examples above so you know they work correctly before moving on
Give as accurate BigOh an analysis as you can of the expected running time of each algorithm.
Once you know the algorithms work correctly, make another cpp file named RuntimeAnalyzer that contains
the same helper methods. Modify each helper method so that it returns the number of assignment statements
that it performs rather than the maximum sum over all subarrays. Do this by adding a counter to each
algorithm that starts at and increments each time you do an assignment statement. You should decide what
qualifies as an assignment statement. Be consistent across algorithms so you can compare the algorithms
against each other.
In the main method of this file will run your algorithms for randomly generated arrays of size
up to Each array should have random values between and inclusive, and you can have
duplicates. To generate a random number between x and y use the randIntmin max method written in
the code below. For each array size, generate arrays one at a time and run the algorithms with each
array, averaging the returned number of assignment statements executed for each algorithm separately.
Your program should output your results in tabular format
Based on the curves, determine the runtime complexity in big O notation of each algorithm. Enter your
answers in a comment at the beginning of each helper method of the RuntimeAnalyzer class. Your answer
should include the runtime complexity and a short explanation of why you believe your answer is correct
based on the algorithm given.
Create a third program ExperimentalRuntimeAnalyzer that contains the same helper methods. In the main
method of this file will run your algorithms for randomly generated arrays of sizes
to Repeat each experiment times and take the average.
Once you complete your third program and generate your final data, enter the data into a spreadsheet and plot
one graph for each algorithm, comparing the number of data value
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
