Question: Sec 1 1 . 5 : # 2 6 You might think that n 1 multiplications are needed to compute x n , since x
Sec : # You might think that n multiplications are needed to compute x n since x n x x x But observe that, for instance, since x x x x x Note: in binary, is Thus x can be computed using three multiplications: one to compute x one to compute x and one to multiply x times x Similarly, since x x x x x x x Note: in binary, is So x can be computed using five multiplications. These potential patterns can be rewritten as: x x x x x x x x x aCredit given for attempting only, please give it a try if you dont have a good idea where to start, please reach out to me for help Write an algorithm to take a real number x and a positive integer n and compute x n As you build the algorithm, note the relationship between the binary representation of n and the x i terms that are included in the product. Remember that we can shift the binary digits of a number to the right by dividing by truncating to keep the value an integer bAnalyze your algorithm in part a and determine the number of multiplications performed in terms of the value of n How does it compare with the optimal solution of logn
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
