Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FindMax ( ( a 0 , a 1 , dots, a n - 1 ) ) : largest = a 0 for i = 1

FindMax ((a0,a1,dots,an-1)) :
largest =a0
for i=1,dots,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,dots,at)
Fill in the blanks of the proof that the loop invariant is correct:
The proof will be by using: induction
Base Case: After 0 iterations of the for loop (before the loop begins:)
Inductive Hypothesis: Assume that for some k, with k>0, that after k-1 iterations, largest is equal to the maximum of Inductive Step: in the k th iteration, there are 2 cases:
Case 1: largest ak By the induction hypothesis largest is the maximum of
and since ,ak largest, ak is the max of (a0,dots,ak). largest =ak,
Case 2: largest >ak By the induction hypothesis largest is the maximum of
and since ak largest, largest is the max of (a0,dots,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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago