Question: Problem 1 (15 pts): Exponentiation by squaring Below is the pseudocode for exponentiation by squaring Precondition: n 0 int power (int m, int n) [

 Problem 1 (15 pts): Exponentiation by squaring Below is the pseudocodefor exponentiation by squaring Precondition: n 0 int power (int m, int

Problem 1 (15 pts): Exponentiation by squaring Below is the pseudocode for exponentiation by squaring Precondition: n 0 int power (int m, int n) [ int y = n; int result-1; if (y is even) I y y/2; = else t result result#x; y y-1; return result; Postcondition : result = m^n 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 teration, 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!