Question: Consider the following algorithm. Input: Integers a > 0, and b 0 Output: (3^b) BigExponent( a , b ) result
Consider the following algorithm.
Input: Integers a > 0, and b 0
Output: (3^b)
BigExponent(a, b)
result <- a // line 1
for i <- 1 to b do // line 2
result<- result * result * result // line 3
return result // line 4
Prove by induction on i that after the ith iteration of the for loop (lines 2 and 3), where the 1st iteration is the iteration when i = 1, the variable result contains the value (3). (Note that once we have proved this statement, we can say that the for loop exits after the iteration when i = b, and so result contains (3), which is returned in line 4.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
