Question
Consider computing ( bn mod m). There is a non-recursive version to compute this function. The pseudocode for the function me below using computes this
Consider computing ( bn mod m). There is a non-recursive version to compute this function. The pseudocode for the function me below using computes this value using a modular exponentiation technique.
procedure me (b: integer,
n = (ak-1 ak-2 a1 a0) 2 ,
m: positive integer)
x = 1
power = b mod m
for I = 0 to k -1
if ai = 1 then x = ( x*power) mod m
power = (power*power) mod m
return x
This may also be expressed recursively as
procedure me (b: integer, n: integer m: integer) // with b>0 and m ?2, n ?0
if n = 0 then
return 1
else if n is even
return me(b, n/2, m)2 mod m
else
return (me(b ,floor( n/2), m)2 mod m * b mod m) mod m
Explain the benefits of expressing and implementing the algorithm recursively. Be sure to quantify your answer. Give an example to illustrate any potential savings or costs of the recursive approaches
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started