Question: FindMax ( ( a 0 , a 1 , dots, a n - 1 ) ) : largest = a 0 for i = 1
FindMax dots, :
largest
for dots,:
largest :
largest
return largest
Consider the loop invariant:
After iterations, largest is equal to the maximum of dots,
Fill in the blanks of the proof that the loop invariant is correct:
The proof will be by using: induction
Base Case: After iterations of the for loop before the loop begins:
Inductive Hypothesis: Assume that for some with that after iterations, largest is equal to the maximum of Inductive Step: in the th iteration, there are cases:
Case : largest By the induction hypothesis largest is the maximum of
and since largest, is the max of dots, largest
Case : largest By the induction hypothesis largest is the maximum of
and since largest, largest is the max of dots,
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
