Answered step by step
Verified Expert Solution
Link Copied!

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 n-digit numbers, a and b.
Output: Product of a and b.
For example,
1986= a
x 2020= b
---------
0000
3972
0000
+3972
---------
4011720= a x b
This is the algorithm you learned in elementary school. Notice it takes O(n^2) time.
A divide-and-conquer solution to solve this problem is: We divide each integer into their left and right halves, which are n/2 digits long.
For example, a =1986, b =2020
aL =19|86= aR
bL =20|20= 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 n/2-digit multiplications aL bL, aL bR, aR bL, and aR bR, and add.
Algorithm Divide-Mult(a,b):
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 x1 hold Divide-Mult(aL, bL).
Let x2 hold Divide-Mult(aL, bR).
Let x3 hold Divide-Mult(aR, bL).
Let x4 hold Divide-Mult(aR, bR).
return x1*10n +(x2+ x3)*10n/2+ x4.
end of if
Analyze the code and provide a "Big-O" 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 divide-and-conquer algorithm?
O()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

Students also viewed these Databases questions