Question: 6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional

 6. Consider the following basic problem. You're given an array A

6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i j, so it doesn't matter what is output for these values.) Here's a simple algorithm to solve this problem For 1, 2, , n For j-i+1, i+ 2, . . . , n Add up array entries A[i] through Aj] Store the result in B[i,j] Endfor Endfor (a) For some function f that you should choose, give a bound of the form O(f (n)) on the running time of this algorithm on an input of size n (i.e., a bound on the number of operations performed by the algorithm). For this same function f, show that the running time of the algorithm on an input of siZe n 1s also S2(f(n)). (This shows an asymptotically tight bound of (f(n)) on the running time.) Although the algorithm you analyzed in parts (a) and (b) is the most natural way to solve the problem-after all, it just iterates through the relevant entries of the array B, filling in a value for each-it contains some highly unnecessary sources of inefficiency. Give a different algorithm to solve this problem, with an asymptotically better running time. In other words, you should design an algorithm with running time O(g(n)), where limnoo g(n)/f(n) . (b) (c)

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!