Let A[1..n] be an array with n elements. Consider the Prefix-Average algorithm,
ID: 3722562 • Letter: L
Question
Let A[1..n] be an array with n elements. Consider the Prefix-Average algorithm, with the pseudocode below 1, 8 = 0 2. let B[1...n] be a new array 3, for j = 1 to n 5. print s Which of the following is the correct loop invariant for the for loop? O 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 O At the start of each iteration j of the for loop, s represents the average of the elements in the prefix subarray Al1.j1. O At the start of each iteration j of the for loop, s represents the average of the elements in the prefix subarray AlO.j]. O 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].Explanation / Answer
second option is correct , can be s->{0 ..j-1} or {1...j} depending on iteration strarting index
Below is the correct sudo code screenshot of prefix-Average algorithm.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.