Karatsuba algorithm: Difference between revisions

Content deleted Content added
m Algorithm: typos
Line 15:
::= ''x''<sub>1</sub>''y''<sub>1</sub>''B''<sup>2''m''</sup> + (''x''<sub>1</sub>''y''<sub>2</sub> + ''x''<sub>2</sub>''y''<sub>1</sub>)''B''<sup>''m''</sup> + ''x''<sub>2</sub>''y''<sub>2</sub>
 
The standard method is to multiply the four subproducts seperatelyseparately, then finally shift and add; this is O(n<sup>2</sup>). However, Karatsuba observed that we can compute ''xy'' in only three multiplications:
 
:Let ''X'' = ''x''<sub>1</sub>''y''<sub>1</sub>
Line 30:
To compute these three products of ''m''-digit numbers, we can employ Karatsuba multiplication again, effectively using [[recursion]]. The shifts, additions and subtractions take linear time respectively, and can be considered negligible.
 
Karatsuba multiplication works best when the two operands are of similar size; thus while one can theoretically choose ''m'' arbitrarily, the best time bound would be acheivedachieved by choosing ''m'' such that the subproducts are roughly equal, that is setting ''m'' to be about ''n''/2.
 
==Example==