Question: Do the same as algorithm 1 , but now calculate the sum of the 2 element array right after you calculate the 1 element array,

Do the same as algorithm 1, but now calculate the sum of the 2 element array right after you calculate the 1 element array, and same thing with the 3 element array.
Once you compute the sum of the subarray from A[i] to A[j], the sum of the subarray from A[i] to A[j+1] is just the previous sum you computed plus A[j+1]. Dont add up all of the previous values all over again.

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!