*********I need question 6 answered which is from question 5 which is *********
Question 5 : Program Correctness I (1 point)
Use the loop invariant (I) to show that the code below correctly computes
n P−1 k=0 2k
(this sum represents the sum of the first n even integers where n ≥ 1).
Algorithm 1 evenSum(int n)
1: p = 2(n − 1)
2: i = n − 1
3: while i > 0 do
4: //(I) p = nP−1 k=i 2k
5: i − −
6: p = p + 2i
7: end while
8: return p
Prove the Base case of the loop invariant (I):
Question 6 : Program Correctness II (4 point )
(a) Inductive step:
i. (1 point) What is your inductive hypothesis?
ii. (1 point) What are you trying to prove?
iii. (1 point) Complete the proof:
(b) Termination step:
i. (1/2 point) What is the value of i when the loop terminates? i =____________
ii. (1/2 point) Plug your answer from the previous question into (I) to show the loop is correct:
PLEASE LIKE THE SOLUTION
FEEL FREE TO DISCUSS IN COMMENT SECTION
SOLUTION
Get Answers For Free
Most questions answered within 1 hours.