Math 2.0

Computer science Definition

Karatsuba algorithm

Builds on AlgorithmDivide-and-conquer algorithm

Definition

Fix an integer base B≥2B \ge 2. The Karatsuba algorithm is the recursive algorithm that computes the product xyxy of two non-negative integers x,yx, y as follows.

  1. If x<Bx < B or y<By < B, compute xyxy directly.
  2. Otherwise, let k≥1k \ge 1 be the least integer with x,y<B2kx, y < B^{2k}, and write x=x1Bk+x0x = x_1 B^k + x_0 and y=y1Bk+y0y = y_1 B^k + y_0 with 0≤x0,y0<Bk0 \le x_0, y_0 < B^k.
  3. Compute recursively z2=x1y1z_2 = x_1 y_1, z0=x0y0z_0 = x_0 y_0 and z3=(x1+x0)(y1+y0)z_3 = (x_1 + x_0)(y_1 + y_0).
  4. Return z2B2k+(z3−z2−z0)Bk+z0z_2 B^{2k} + (z_3 - z_2 - z_0) B^k + z_0.

The output is correct because z3−z2−z0=x1y0+x0y1z_3 - z_2 - z_0 = x_1 y_0 + x_0 y_1, so the returned number equals (x1Bk+x0)(y1Bk+y0)(x_1 B^k + x_0)(y_1 B^k + y_0).

Remarks

Example: with B=10B = 10, x=12x = 12, y=34y = 34 and k=1k = 1, one gets z2=3z_2 = 3, z0=8z_0 = 8 and z3=3⋅7=21z_3 = 3 \cdot 7 = 21. The result is 3⋅100+(21−3−8)⋅10+8=408=12⋅343 \cdot 100 + (21 - 3 - 8) \cdot 10 + 8 = 408 = 12 \cdot 34.

Non-example: computing the four products x1y1x_1 y_1, x1y0x_1 y_0, x0y1x_0 y_1, x0y0x_0 y_0 recursively is also correct, but it is not the Karatsuba algorithm. Its cost satisfies T(n)=4T(n/2)+O(n)T(n) = 4 T(n/2) + O(n), which gives only O(n2)O(n^2).

For nn-digit inputs with kk about n/2n/2, the cost of the Karatsuba algorithm satisfies T(n)=3T(n/2)+O(n)T(n) = 3 T(n/2) + O(n). By the master theorem, T(n)=O(nlog⁡23)T(n) = O(n^{\log_2 3}) in asymptotic notation.

Reading path

To understand this page from the ground up, read these 3 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Algorithm concept
  2. Divide-and-conquer algorithm concept
  3. Karatsuba algorithm definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Karatsuba_algorithm
About this page
TagEHH9KQHYFA
URIm2://EHH9KQHYFA
Kinddefinition
WritingW0 stub
MSC68W30, 68W40, 11Y16
DefinesKaratsuba algorithm
UsesAlgorithm, Divide-and-conquer algorithm
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.