(Solved) : 4 Consider Following Algorithm Attempts Compute Value Y Non Zero Real Number Y Non Negativ Q44123857 . . .

4. Consider the following algorithm that attempts to compute the value y” for any non-zero real number y and any non-negative integer n. (n Z) A (n > 0) Algorithm 4 1: //pre: (YER) A (y + 0) 2: answer1 3: it1 1: //LoopInv: 5: while i<n do 6: answer answer * y 7: iti+1 8: end while 9://post: answer ==y” (a) [8 marks) Prove that Algorithm 4 satisfies the Partial Correctness property. You will need to provide (and prove) your own loop invariant LoopInv for line 4. (b) 14 marks Prove that Algorithm 4 satisfies the Termination property. Show transcribed image text 4. Consider the following algorithm that attempts to compute the value y” for any non-zero real number y and any non-negative integer n. (n Z) A (n > 0) Algorithm 4 1: //pre: (YER) A (y + 0) 2: answer1 3: it1 1: //LoopInv: 5: while i
Expert Answer
Answer to 4. Consider the following algorithm that attempts to compute the value y” for any non-zero real number y and any non-neg…
OR