Question

In: Computer Science

Develop a recursive algorithm that multiply two integer numbers x and y, where x is an...

Develop a recursive algorithm that multiply two integer numbers x and y, where x is an m-bit number and y is an n-bit number (10 points), and analyze the time complexity of this algorithm (10 points).

Solutions

Expert Solution

let and

we can write x and y as:

assuming botm m and n are power of 2.

now their product is

where xl,yl, xryl, xlyr, xryr are multiplication of m/2 and n/2 digit numbers.

So we have reduced the bigger problem into 4 smaller subproblems of same type

The algo is:

Multiply (x,y,m,n)

xl=left half of x

xr= right half of x

yl=left half of y

yr=right half of y

return Multiply(xl,yl,m/2,n/2)+2m/2Multiply(xr,yl,m/2,n/2)+2n/2Multiply(xl,yr,m/2,n/2)+2(m+n)/2Multiply(xr,yr,m//2,n/2)

Note. multiplying a binary number by 2k is equivalent of shifting the number right to k positions. so multiplying a binary number by 2k takes constan time:

with this the recurrence is given by

T(m,n)=4T(m/2,n/2)+O(n+m) (4 subproblems of size m/2 and n/2 taking linear time to multiply bt 2^k)

which is O(nm)


Related Solutions

in code c++ describe a recursive algorithm for multiplying two nonnegative integers x and y based...
in code c++ describe a recursive algorithm for multiplying two nonnegative integers x and y based on the fact that xy = 2(x · (y/2)) when y is even and xy = 2(x · ⌊y/2⌋) + x when y is odd, together with the initial condition xy = 0 when y = 0.
Write a recursive method pow(x, y) to calculate xy, where x and y are positive integers....
Write a recursive method pow(x, y) to calculate xy, where x and y are positive integers. If x=2, y=4, the method pow should return 16. Java answers only please.
Now we need to develop a recursive algorithm for multiplication operation with two positive integers without...
Now we need to develop a recursive algorithm for multiplication operation with two positive integers without using the multiplication operator. Your answer should be in pseudocode or Java code format. Then use the Three-Question Approach to verify your recursive algorithm. No coding is required for this assignment 1. The Base-Case Question Is   there   a   nonrecursive   way   out   of   the   algorithm,   and   does   the   algorithm   work   correctly   for   this   base   case? 2. The Smaller-Caller Question Does   each   recursive   call   to   the  ...
a. Design a recursive algorithm for computing 3n for any nonnegative integer n that is based...
a. Design a recursive algorithm for computing 3n for any nonnegative integer n that is based on the formula 3n = 3n−1 + 3n−1 + 3n−1 b. Set up a recurrence relation for the number of additions made by the algorithm and solve it. c. Draw a tree of recursive calls for this algorithm and count the number of calls made by the algorithm. d. Is it a good algorithm for solving this problem?
Sample Execution : ** Recursive Euclidean Algorithm to calculate GCD ** Type a positive integer for...
Sample Execution : ** Recursive Euclidean Algorithm to calculate GCD ** Type a positive integer for A: -2 Sorry, you must enter a positive integer (>0). Please try again. ** Recursive Euclidean Algorithm to calculate GCD ** Type a positive integer for A: 35 Type a positive integer for B: 63 The GCD is 7 Write a MIPS assembly program that prompts the user for 2 positive integers (>0). Then it uses the Recursive Euclidean Algorithm to calculate GCD (the...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns,...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns, as output, the sum of the first n positive odd integers. Your solution should be recursive, and it should not contain any "for" loops or "while" loops.
Develop, write and certify a properly recursive procedure reverseDigits to input a positive integer n and...
Develop, write and certify a properly recursive procedure reverseDigits to input a positive integer n and to output the integer formed by reversing the digits of n. Thus (reverseDigits 1234) returns the integer 4321. Please answer using Dr Racket(R5RS language)
Write a recursive function named multiply that takes two positive integers as parameters and returns the...
Write a recursive function named multiply that takes two positive integers as parameters and returns the product of those two numbers (the result from multiplying them together). Your program should not use multiplication - it should find the result by using only addition. To get your thinking on the right track: 7 * 4 = 7 + (7 * 3) 7 * 3 = 7 + (7 * 2) 7 * 2 = 7 + (7 * 1) 7 *...
Two numbers x and y that are not machine numbers are read into a 32-bit word-length...
Two numbers x and y that are not machine numbers are read into a 32-bit word-length computer. The machine computes to xy2. what sort of relative error can be expected? Assume no underflow or overflow
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . ,...
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . , an which are known to be bounded by n 2 (so ai ≤ n 2 , for every i = 1, . . . , n. Use the idea of Radix Sort (discussed in class and presented in Section 8.3 in the textbook). Illustrate your algorithm by showing on paper similar to Fig. 8.3, page 198 in the textbook (make sure you indicate clearly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT