Fast Multiplication

Learn about the efficiency and effectiveness of the fast multiplication algorithm.

The divide-and-conquer algorithm

Two ancient algorithms for multiplying two nn-digit numbers in O(n2)O(n^2) time are: the grade-school lattice algorithm and the Egyptian peasant algorithm. Maybe, we can get a more efficient algorithm by splitting the digit arrays in half and exploiting the following identity:

(10ma+b)(10mc+d)=102mac+10m(bc+ad)+bd(10^ma + b)(10^mc + d) = 10^{2m}ac + 10^m(bc + ad) + bd

This recurrence immediately suggests the following divide-and-conquer algorithm to multiply two nn-digit numbers, xx and yy. Each of the four subproducts ac,bc,ad,ac, bc, ad, and bdbd is computed recursively, but the multiplications in the last line aren’t recursive because we can multiply by a power of ten by shifting the digits to the left and filling in the correct number of zeros, all in O(n)O(n) time.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy