Problem

In Section 2.1 we described an algorithm that multiplies two n-bit binary integers x and y...

In Section 2.1 we described an algorithm that multiplies two n-bit binary integers x and y in time na, where a = log2 3. Call this procedure fastmultiply (x, y).

(a) We want to convert the decimal integer 10n (a 1 followed by n zeros) into binary. Here is the algorithm (assume n is a power of 2):

function pwr2bin(n)

    if n = 1: return 10102

    else:

       z = ???

       return fastmultiply(z, z)

Fill in the missing details. Then give a recurrence relation for the running time of the algorithm, and solve the recurrence.


(b) Next, we want to convert any decimal integer x with n digits (where n is a power of 2) into binary. The algorithm is the following:

function dec2bin(x)

   if n = 1: return binary[x]

   else:

      split x into two decimal numbers xL, xR with n/2

           digits each

      return ???

 

Here binary [∙] is a vector that contains the binary representation of all one-digit integers. That is, binary[0] = 02, binary[1] = 12, up to binary[9] = 10012. Assume that a lookup in binary takes O(1) time. Fill in the missing details. Once again, give a recurrence for the running time of the algorithm, and solve it.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT