Question: Sec 1 1 . 5 : # 2 6 You might think that n 1 multiplications are needed to compute x n , since x

Sec 11.5: #26 You might think that n 1 multiplications are needed to compute x n , since x n = x x x But observe that, for instance, since 6=4+2, x 6= x 4x 2=(x 2)2x 2.(Note: in binary, 6 is 110) Thus x 6 can be computed using three multiplications: one to compute x 2, one to compute (x 2)2, and one to multiply (x 2)2 times x 2. Similarly, since 11=8+2+1, x 11= x 8x 2x 1=((x 2)2)2x 2x (Note: in binary, 11 is 1011) So x 11 can be computed using five multiplications. These potential patterns can be rewritten as: x 6= x 122 x 121 x 020 x 11= x 123 x 022 x 121 x 120 a.(Credit 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 5 x n . As you build the algorithm, note the relationship between the binary representation of n and the x 2 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 2(truncating to keep the value an integer) b.Analyze 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 log2(n)

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 Programming Questions!