Karatsuba algorithm: Difference between revisions

Content deleted Content added
Line 22:
 
==Complexity==
If ''T''(''n'') denotes the time it takes to multiply two ''n''-digit numbers with Karatsuba's method, then we can write
 
:''T''(''n'') = 3 ''T''(''n''/2) + ''cn'' + ''d''
 
for some constants ''c'' and ''d'', and this [[recurrence relation]] can be solved using the [[master theorem]], giving a time complexity of Θ(''n''<sup>ln(3)/ln(2)</sup>). The number ln(3)/ln(2) is approximately 1.585, so this method is significantly faster than long multiplication. Because of the overhead of recursion, Karatsuba's multiplication is slower than long multiplication for small values of ''n''; typical implementations therefore switch to long multiplication if ''n'' is below some threshold.
 
Implementations differ greatly on what the crossover point is when Karatsuba becomes faster than the classical algorithm, but generally numbers over 2<sup>320</sup> are faster with Karatsuba. [http://www.swox.com/gmp/manual/Karatsuba-Multiplication.html][http://ozark.hendrix.edu/~burch/proj/karat/comment1.html] Karatsuba is surpassed by the asymptotically faster [[Schönhage-Strassen algorithm]] around 2<sup>33,000</sup>.
 
==An Objective Caml implementation==