Question: Consider the following algorithm that returns the maximum of a list of distinct positive integers ( a 0 , . . . . , a

Consider the following algorithm that returns the maximum of a list of distinct positive integers
(a0,....,an-1)
FindMax(a0,a1,...an-1)):
largest = a0
for i =1,... n-1:
if largest = ai :
largest = ai
return largest
Consider the loop invariant:
After t iterations, largest is equal to the maximum of (a0,a1,...at)
Fill in the blanks of the proof t _______(regular/strong)induction
Base Case: After 0 iterations of the for loop (before the loop begins:)___________(largest is smaller than a_0, largest is maximum of the empty list, largest is maximum of the list [a_0,a_1, largest is maximum of the list [a_0])
Inductive Hypothesis: Assume that for some k, with k>0, that after k-1 iterations, largest is equal to the maximum of _________[(a_1,...a_k),(a_1,...,a_(k-1)),(a_0,...a_k),(a_0,...a_(k-1))]
Inductive Step: in the k th iteration, there are 2 cases:
Case 1: largest ak By the induction hypothesis largest is the maximum of ________[(a_1,...a_k),(a_1,...,a_(k-1)),(a_0,...a_k),(a_0,...a_(k-1))]
and since ,ak largest, ak
Case 2: largest >ak By the induction hypothesis largest is the maximum of _______[(a_1,...a_k),(a_1,...a_(k-1)),(a_0,...a_k),(a_0,...a_(k-1))]
and since ,ak largest, is the max of (a0,...ak)
 Consider the following algorithm that returns the maximum of a list

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!