Question: Consider the integer multiplication problem. Input: Two n - digit numbers, a and b . Output: Product of a and b . For example, 1
Consider the integer multiplication problem.
Input: Two ndigit numbers, a and b
Output: Product of a and b
For example,
a
x b
a x b
This is the algorithm you learned in elementary school. Notice it takes On time.
A divideandconquer solution to solve this problem is: We divide each integer into their left and right halves, which are n digits long.
For example, a b
aL aR
bL bR
Then the product of a and b can then be obtained as:
aL aR
x bL bR
aL bR aR bR
aL bL aR bL
aL bL aL bR aR bL aR bR
So our algorithm is to compute four ndigit multiplications aL bL aL bR aR bL and aR bR and add.
Algorithm DivideMultab:
if a or b has one digit, then:
return a b
else:
Let n be the number of digits in max a b
Let aL and aR be left and right halves of a
Let bL and bR be left and right halves of b
Let x hold DivideMultaL bL
Let x hold DivideMultaL bR
Let x hold DivideMultaR bL
Let x hold DivideMultaR bR
return xn x xn x
end of if
Analyze the code and provide a "BigO estimate of its running time in terms of n
What is the recurrence equation of the time complexity?
What is the time complexity of the above divideandconquer algorithm?
O
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
