is anyone possible give me advice how I have to prove this by induction and proo
ID: 3667232 • Letter: I
Question
is anyone possible give me advice how I have to prove this by induction and proof by conttadiction?? I have to do with this find max function I understand how this function work but still not sure how to prove it..
Explanation / Answer
Precondition: like base case.
CurrentMax = arr[0] or arr.
Loop invariant(Induction Step): if true at step i, still true
after one more loop.
Suppose CurrentMax is the max of arr[0..i- 1].
Two cases:
a) arr[i]> CurrentMax. Then CurrentMax is the max of A[0..i] since it is in the array
(arr[i]) and it is the largest (> than previous).
b) arr[i] is not > than CurrentMax. Then CurrentMax is the max of arr[0..i] since it
was the max of arr[0..i- 1] and arr[i] is not bigger.
By induction, true for all iterations including
termination.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.