The algorithm below computes the maximum value in an array A [1..n] with n eleme
ID: 3844362 • Letter: T
Question
The algorithm below computes the maximum value in an array A [1..n] with n elements: COMPUTE-MAX (A.n) max = - infinity for i = 1 to n if A [i] > max max = A [i] return max Which of the following is the correct loop invariant of the for loop? At the start of each iteration i of the for loop, max is the maximum value in the subarray A [1..i]. At the start of each iteration i of the for loop, max is the maximum value in the subarray A [1..n]. At the start of each iteration i of the for loop, max is the maximum value in the subarray A [1..n]. At the start of each iteration i of the for loop, max is the maximum value in the subarray A [1..i - 1]. At the start of each iteration i of the for loop, max is the maximum value in the subarray A [i - 1..n].Explanation / Answer
At the start of the each iteration i of the for loop ,max is the maximum value in the subarray A[1...i-1];
This is the correct loop invariant of the for loop
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.