Question: Let A[1..n] be an array with n elements. Consider the Prefix-Average algorithm, with the pseudocode below. Prefix-Average(A,n) s = 0 let B[1n] be a new

Let A[1..n] be an array with n elements. Consider the Prefix-Average algorithm, with the pseudocode below.

Prefix-Average(A,n)

Let A[1..n] be an array with n elements. Consider the Prefix-Average algorithm,s = 0

let B[1n] be a new array

for j = 1 to n

with the pseudocode below. Prefix-Average(A,n) s = 0 let B[1n] be as=s(j1)+A[j]j

print new array for j = 1 to n s=s(j1)+A[j]j print s Whichs

Which of the following is the correct loop invariant for the for loop?

At the start of each iteration j of the for loop, s represents the average of the elements in the prefix subarray A[1..j+1].

At the start of each iteration j of the for loop, s represents the average of the elements in the prefix subarray A[0..j].

At the start of each iteration j of the for loop, s represents the average of the elements in the prefix subarray A[1..j-1].

At the start of each iteration j of the for loop, s represents the average of the elements in the prefix subarray A[1..j].

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!