Question: Below is the pseudocode for exponentiation by squaring Precondition: n >0 int power (int m, int n) ( int y - n; int result- 1;

 Below is the pseudocode for exponentiation by squaring Precondition: n >0

Below is the pseudocode for exponentiation by squaring Precondition: n >0 int power (int m, int n) ( int y - n; int result- 1; while (y !- 0) if (y is even) else result result#x; - return result; Postcondition: result mn a) Find a suitable loop invariant. (3 pts) b) Show that the invariant holds before the loop (base case). (2 pts) c) Show by induction that if the invariant holds after k-th iteration, and execution takes a k+1-st iteration, the invariant still holds (inductive step). (6 pts) d) Show that the loop exit condition and the loop invariant imply the postcondition result - m*n. (2 pts) e) Find a suitable decrementing function. Show that the function decreases at each iteration and that when it reaches a minimum the loop is exited. (2 pts)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!