Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

Compute 1 2 x 2 f ( 1 + x 3 ) d x given that 0 9 f ( x ) d x = 6 .

Answered: 1 week ago

Question

Language in Context?

Answered: 1 week ago