Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started