Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions