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

Use Booth’s algorithm to multiply the 4-bit numbers, x and y, below, represented in twos complement....
Use Booth’s algorithm to multiply the 4-bit numbers, x and y, below, represented in twos complement. Show all your work. x = 0110, y = 0011 x = 0110, y = 1101 x = 1010, y = 0011 x = 1010, y =1101
develop a recursive function to compute LCS (x,y)
develop a recursive function to compute LCS (x,y)
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.
1. Implement the faster algorithm for integer multiplication in C++ as a function, called “multiply”, that...
1. Implement the faster algorithm for integer multiplication in C++ as a function, called “multiply”, that takes 2 unsigned integers and returns their multiplication as an unsigned integer. 2. Test your code in main. Hints: Represent integers as strings. Write a utility function that pads integers with zeros, this will be useful If the 2 integers differ in length In calculating ??10^? and (??+??) 10^(?/2)
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.
Given a positive integer n, write a recursive algorithm that returns the number of the digits...
Given a positive integer n, write a recursive algorithm that returns the number of the digits in n. For example, if the given number n is 12345, the algorithm should return 5. What is the time complexity of your algorithm? use java
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT