Question: By mathematical induction, prove that the following loop will add n elements in an array a[] and store the sum in the variable sum.
By mathematical induction, prove that the following loop will add n elements in an array a[] and store the sum in the variable "sum". sum = 0 k=0 while k < n sum = sum + a[k] k = k +1 State what you want to prove: State the loop invariant P(k): Show the initialization, i.e., P(0) is true: Show the maintenance step that assumes P(k) is true and proves that P(k+1) is true: Show the termination, and that it implies what you want to prove:
Step by Step Solution
3.39 Rating (146 Votes )
There are 3 Steps involved in it
Answer What we want to prove For the given loop sum 0 k 0 while k n sum sum ak k k 1 Sure lets perfo... View full answer
Get step-by-step solutions from verified subject matter experts
