AlgorithmProject
AlgorithmProject
ENGINEERING
Computer Engineering Department
Section:2
Name ID
1
Introduction:
2
Divide and Conquer Approach:
Large integer multiplication using the divide and conquer method
involves a systematic process of breaking down the problem into smaller
sub-problems, solving them individually, and then combining the results
to obtain the final product. Here is a detailed explanation of the divide
and conquer methodology in the context of large integer multiplication,
along with a breakdown of the algorithmic steps involved:
1.Divide:
•Split the input integers, each with n digits, into two equal-sized halves.
Let's denote them as A and B.
•Express the original multiplication problem (A * B) as four sub-
problems: A₁ * B₁, A₁ * B₂, A₂ * B₁, and A₂ * B₂.
2.Conquer:
•Recursively compute the four sub-products using the same divide and
conquer approach until reaching base cases.
•The base case is often when the input integers have a small number of
digits, where direct multiplication becomes more efficient.
3.Combine:
•Combine the results of the sub-problems to obtain the final product.
•The combination step involves arithmetic operations and additions to
reconstruct the overall multiplication outcome.
3
Algorithm design:
•The algorithm divides the input integers into two halves to create sub-
problems. This choice simplifies the overall computation and aligns with the
essence of the divide and conquer paradigm.
2.Base Case:
•The base case checks if the integers are single-digit, at which point direct
multiplication is performed. This ensures that the algorithm efficiently handles
smaller sub-problems.
3.Recursion:
•The algorithm recursively applies the divide and conquer approach to solve
sub-problems. The recursive calls are made for each pair of divided sub-
integers.
4.Combination Step:
4
5.SplitAt Helper Function:
The splitAt function simplifies the process of dividing large integers into two
halves. It is a crucial component for the divide step and enhances the
readability of the algorithm.
5
Implementation:
Below is a simplified Python implementation of the divide and
conquer algorithm for large integer multiplication:
6
•Multiply A1 by B1 to get the high-order part of the
product (A1 * B1 = 12 * 56).
•Multiply A2 by B2 to get the low-order part of the
product (A2 * B2 = 34 * 78).
3.Multiply and add for the middle parts of the product:
•Multiply A1 by B2 and A2 by B1, then add them together
((A1 * B2) + (A2 * B1) = (12 * 78) + (34 * 56)).
3.Combine the sub-results to get the final product:
•The high-order product (from step 2) needs to be shifted
left by the total number of digits (in this case, 4, since each
half has 2 digits).
•The middle-order product (from step 3) needs to be
shifted left by the number of digits in one half (2 in this
case).
•The low-order product (from step 2) remains as is.
So the final result is calculated as:
Final Product=(A1×B1)×104+((A1×B2)+(A2×B1))×102+(A2×B2)
Final Product=(12×56)×104+((12×78)+(34×56))×102+(34×78)
•High-order product (A1 * B1) = 672
7
Complexity Analysis:
1.Time Complexity:
8
2.By breaking down the problem into smaller parts, the algorithm
achieves optimal performance, especially for large integers where
the time savings become more pronounced.
Potential Trade-offs:
1.Implementation Complexity:
3.Crossover Point:
There exists a crossover point where the divide and conquer
method becomes more efficient than traditional methods. This
point depends on factors such as the specific algorithm
9
implementations, hardware architecture, and the size of the input
integers.
Conclusion:
In conclusion, this exploration into large integer multiplication
using the divide and conquer approach has yielded key findings
and insights into algorithmic efficiency and design. The analysis
and implementation of the divide and conquer algorithm revealed
its significance in addressing challenges posed by the
multiplication of large integers. Here are the key findings:
1. Efficiency Gains:
•The divide and conquer approach, when applied to large
integer multiplication, demonstrates significant efficiency
gains compared to traditional quadratic algorithms like
schoolbook multiplication. The reduction in time complexity
to O(n^log₂3) positions it as a valuable strategy for handling
extremely large integers.
10