This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Computational complexity of mathematical operations" – news ·newspapers ·books ·scholar ·JSTOR(April 2015) (Learn how and when to remove this message) |
This article needs editing tocomply with Wikipedia'sManual of Style. In particular, it has problems withMOS:FORMULA - avoid mixing <math>...</math> and{{math}} in the same expression. Please helpimprove the content.(July 2025) (Learn how and when to remove this message) |

The following tables list thecomputational complexity of variousalgorithms for commonmathematical operations.
Here, complexity refers to thetime complexity of performing computations on amultitape Turing machine.[1] Seebig O notation for an explanation of the notation used.
Note: Due to the variety of multiplication algorithms, below stands in for the complexity of the chosen multiplication algorithm.
This table lists the complexity of mathematical operations on integers.
| Operation | Input | Output | Algorithm | Complexity |
|---|---|---|---|---|
| Addition | Two-digit numbers | One-digit number | Schoolbook addition with carry | |
| Subtraction | Two-digit numbers | One-digit number | Schoolbook subtraction with borrow | |
| Multiplication | Two-digit numbers | One-digit number | Schoolbook long multiplication | |
| Karatsuba algorithm | ||||
| 3-wayToom–Cook multiplication | ||||
| -way Toom–Cook multiplication | ||||
| Mixed-level Toom–Cook (Knuth 4.3.3-T)[2] | ||||
| Schönhage–Strassen algorithm | ||||
| Harvey-Hoeven algorithm[3][4] | ||||
| Division | Two-digit numbers | One-digit number | Schoolbook long division | |
| Burnikel–Ziegler Divide-and-Conquer Division[5] | ||||
| Newton–Raphson division | ||||
| Square root | One-digit number | One-digit number | Newton's method | |
| Modular exponentiation | Two-digit integers and a-bit exponent | One-digit integer | Repeated multiplication and reduction | |
| Exponentiation by squaring | ||||
| Exponentiation withMontgomery reduction |
On stronger computational models, specifically apointer machine and consequently also aunit-cost random-access machine it is possible to multiply twon-bit numbers in timeO(n).[6]
Here we consider operations over polynomials andn denotes their degree; for the coefficients we use aunit-cost model, ignoring the number of bits in a number. In practice this means that we assume them to be machine integers. For this section indicates the time needed for multiplying two polynomials of degree at most.[7]: 242
| Operation | Input | Output | Algorithm | Complexity |
|---|---|---|---|---|
| Polynomial evaluation | One polynomial of degree with integer coefficients | One number | Direct evaluation | |
| Horner's method | ||||
| Polynomial multipoint evaluation | One polynomial of degree less than with integer coefficients and numbers as evaluation points | numbers | Direct evaluation | |
| Fast multipoint evaluation[7]: 295 | ||||
| Polynomial gcd (over or) | Two polynomials of degree with integer coefficients | One polynomial of degree at most | Euclidean algorithm | |
| Fast Euclidean algorithm[7]: 318 (Lehmer[7]: 324 ) |
Many of the methods in this section are given in Borwein & Borwein.[8]
Theelementary functions are constructed by composing arithmetic operations, theexponential function (), thenatural logarithm (),trigonometric functions (), and their inverses. The complexity of an elementary function is equivalent to that of its inverse, since all elementary functions areanalytic and hence invertible by means of Newton's method. In particular, if either or in the complex domain can be computed with some complexity, then that complexity is attainable for all other elementary functions.
Below, the size refers to the number of digits of precision at which the function is to be evaluated.
| Algorithm | Applicability | Complexity |
|---|---|---|
| Taylor series; repeated argument reduction (e.g.) and direct summation | ||
| Taylor series;FFT-based acceleration | ||
| Taylor series;binary splitting +bit-burst algorithm[9] | ||
| Arithmetic–geometric mean iteration[10] |
It is not known whether is the optimal complexity for elementary functions. The best known lower bound is the trivial bound.
| Function | Input | Algorithm | Complexity |
|---|---|---|---|
| Gamma function | Integer | Series approximation of theincomplete gamma function | |
| Fixed rational number | Hypergeometric series | ||
| , for integer. | Arithmetic-geometric mean iteration | ||
| Hypergeometric function | -digit number | (As described in Borwein & Borwein) | |
| Fixed rational number | Hypergeometric series |
This table gives the complexity of computing approximations to the given constants to correct digits.
| Constant | Algorithm | Complexity |
|---|---|---|
| Golden ratio, | Newton's method | |
| Square root of 2, | Newton's method | |
| Euler's number, | Binary splitting of the Taylor series for the exponential function | |
| Newton inversion of the natural logarithm | ||
| Pi, | Binary splitting of the arctan series inMachin's formula | [11] |
| Gauss–Legendre algorithm | [11] | |
| Euler's constant, | Sweeney's method (approximation in terms of theexponential integral) |
Algorithms fornumber theoretical calculations are studied incomputational number theory.
| Operation | Input | Output | Algorithm | Complexity |
|---|---|---|---|---|
| Greatest common divisor | Two-digit integers | One integer with at most digits | Euclidean algorithm | |
| Binary GCD algorithm | ||||
| Left/rightk-ary binary GCD algorithm[12] | ||||
| Stehlé–Zimmermann algorithm[13] | ||||
| Schönhage controlled Euclidean descent algorithm[14] | ||||
| Jacobi symbol | Two-digit integers | , or | Schönhage controlled Euclidean descent algorithm[15] | |
| Stehlé–Zimmermann algorithm[16] | ||||
| Factorial | A positive integer less than | One-digit integer | Bottom-up multiplication | |
| Binary splitting | ||||
| Exponentiation of the prime factors of | ,[17] [1] | |||
| Primality test | A-digit integer | True or false | AKS primality test | [18][19] , assumingAgrawal's conjecture |
| Elliptic curve primality proving | heuristically[20] | |||
| Baillie–PSW primality test | [21][22] | |||
| Miller–Rabin primality test | [23] | |||
| Solovay–Strassen primality test | [23] | |||
| Integer factorization | A-bit input integer | A set of factors | General number field sieve | [nb 1] |
| Shor's algorithm | , on aquantum computer |
The following complexity figures assume that arithmetic with individual elements has complexityO(1), as is the case with fixed-precisionfloating-point arithmetic or operations on afinite field.
| Operation | Input | Output | Algorithm | Complexity |
|---|---|---|---|---|
| Matrix multiplication | Two matrices | One matrix | Schoolbook matrix multiplication | |
| Strassen algorithm | ||||
| Coppersmith–Winograd algorithm (galactic algorithm) | ||||
| Optimized CW-like algorithms[24][25][26][27] (galactic algorithms) | ||||
| One matrix, and one matrix | One matrix | Schoolbook matrix multiplication | ||
| One matrix, and one matrix, for some | One matrix | Algorithms given in[28] | , where upper bounds on are given in[28] | |
| Matrix inversion | One matrix | One matrix | Gauss–Jordan elimination | |
| Strassen algorithm | ||||
| Coppersmith–Winograd algorithm | ||||
| Optimized CW-like algorithms | ||||
| Singular value decomposition | One matrix | One matrix, one matrix, & one matrix | Bidiagonalization and QR algorithm | () |
| One matrix, one matrix, & one matrix | Bidiagonalization and QR algorithm | () | ||
| QR decomposition | One matrix | One matrix, & one matrix | Algorithms in[29] | () |
| Determinant | One matrix | One number | Laplace expansion | |
| Division-free algorithm[30] | ||||
| LU decomposition | ||||
| Bareiss algorithm | ||||
| Fast matrix multiplication[32] | ||||
| Back substitution | Triangular matrix | solutions | Back substitution[33] | |
| Characteristic polynomial | One matrix | One degree- polynomial | Faddeev-LeVerrier algorithm | |
| Samuelson-Berkowitz algorithm | (smaller constant factor) | |||
| Preparata-Sarwate algorithm[34][35] |
In 2005,Henry Cohn,Robert Kleinberg,Balázs Szegedy, andChris Umans showed that either of two different conjectures would imply that the exponent of matrix multiplication is 2.[36]
Algorithms for computingtransforms of functions (particularlyintegral transforms) are widely used in all areas of mathematics, particularlyanalysis andsignal processing.
| Operation | Input | Output | Algorithm | Complexity |
|---|---|---|---|---|
| Discrete Fourier transform | Finite data sequence of size | Set of complex numbers | Schoolbook | |
| Fast Fourier transform |