Question 8 10 pts The algorithm below computes the maximum value in an array A[1
ID: 3890841 • Letter: Q
Question
Question 8 10 pts The algorithm below computes the maximum value in an array A[1..n] with n elements: COMPUTE-MAXIA.n max A[n] for i n-1 downto 1 if Ali]> max max = Ali] 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.n]. At the start of each iteration i of the for loop, max is the maximum value in the subarray A[L-i-1]. At the start of each iteration i of the for loop. max is the maximum value in the subarray A[1. At the start of each iteration i of the for loop, max is the maximum value in the subarray AIi.n]. At the start of each iteration i of the for loop. max is the maximum value in the subarray A[i+1.nj. Question 9 10 pts Arrange the following functions in ascending order of growth rate. That is, if function g(n) immediately follows function f(n) in your list, then f(n)O(g(n)) A(n) = 3n fs (n) = Is (n) = ()', + 3gExplanation / Answer
8. e) At start of each iteration, the max will be equal to maximum of all numbers already processed. as we are starting from n and gowing downwards toward 1, so at start of any i, max will have maximum of values from i+1 to n as i is yet to be checked.
9. Correct order is f2, f6, f5, f3, f4, f1
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.