Menu

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

4. Consider the following algorithm that attempts to compute the value y for any non-zero real number y and any non-negative

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. Algorithm 4 1: //pre: (YER) ^ (y + 0) ^ (n > 0) 2: answer +1 3: i+1 4: //LoopInv: 5: while i<n do 6: answer answer * y 7: ifi +1 8: end while 9://post: answer ==y” (a) 18 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) [4 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. Algorithm 4 1: //pre: (YER) ^ (y + 0) ^ (n > 0) 2: answer +1 3: i+1 4: //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