Problem

Maximum average. Write a program that finds a contiguous subarray of length at most m in a...

Maximum average. Write a program that finds a contiguous subarray of length at most m in an array of n long integers that has the highest average value among all such subarrays, by trying all subarrays. Use the scientific method to confirm that the order of growth of the running time of your program is mn2. Next, write a program that solves the problem by first computing the quantity prefix [i] = a[0] + ... +a[i] for each i, then computing the average in the interval from a[i] to a[j] with the expression (prefix [j] − prefix[i]) / (j − i + 1). Use the scientific method to confirm that this method reduces the order of growth by a factor of n.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 4.1