Question: Find the loop invariant of the code where n 1). Algorithm 1 sum (int n) p=0 i=0 while in do p=p+2*i i++ end while
Find the loop invariant of the code where n 1). Algorithm 1 sum (int n) p=0 i=0 while in do p=p+2*i i++ end while return p (a) (4 points) What does the loop do? Write down a formula with the variable n. Prove the correctness of the loop invariant. (b) (4 points) Basis step (when n = 1): (c) Inductive step: i. (3 points) What is your inductive hypothesis? ii. (3 points) What are you trying to prove? 4 iii. (6 points) Complete the proof:
Step by Step Solution
3.42 Rating (149 Votes )
There are 3 Steps involved in it
The algorithm displayed in the image is aimed at summing a series of numbers which appears to be based on a mathematical formula The loop within the algorithm seems to be calculating a sum based on an ... View full answer
Get step-by-step solutions from verified subject matter experts
