Computational complexity of mathematical operations


The following tables list the computational complexity of various algorithms for common mathematical operations.
Here, complexity refers to the time complexity of performing computations on a multitape Turing machine. See big O notation for an explanation of the notation used.
Note: Due to the variety of multiplication algorithms, M below stands in for the complexity of the chosen multiplication algorithm.

Arithmetic functions

OperationInputOutputAlgorithmComplexity
AdditionTwo n-digit numbers N, NOne n+1-digit numberSchoolbook addition with carryΘ, Θ
SubtractionTwo n-digit numbers N, NOne n+1-digit numberSchoolbook subtraction with borrowΘ, Θ
MultiplicationTwo n-digit numbers
One 2n-digit numberSchoolbook long multiplication
MultiplicationTwo n-digit numbers
One 2n-digit numberKaratsuba algorithm
MultiplicationTwo n-digit numbers
One 2n-digit number3-way Toom–Cook multiplication
MultiplicationTwo n-digit numbers
One 2n-digit number-way Toom–Cook multiplication
MultiplicationTwo n-digit numbers
One 2n-digit numberMixed-level Toom–Cook
MultiplicationTwo n-digit numbers
One 2n-digit numberSchönhage–Strassen algorithm
MultiplicationTwo n-digit numbers
One 2n-digit numberFürer's algorithm
MultiplicationTwo n-digit numbers
One 2n-digit numberHarvey-Hoeven algorithm
DivisionTwo n-digit numbersOne n-digit numberSchoolbook long division
DivisionTwo n-digit numbersOne n-digit numberBurnikel-Ziegler Divide-and-Conquer Division
DivisionTwo n-digit numbersOne n-digit numberNewton–Raphson division
Square rootOne n-digit numberOne n-digit numberNewton's method
Modular exponentiationTwo n-digit integers and a k-bit exponentOne n-digit integerRepeated multiplication and reduction
Modular exponentiationTwo n-digit integers and a k-bit exponentOne n-digit integerExponentiation by squaring
Modular exponentiationTwo n-digit integers and a k-bit exponentOne n-digit integerExponentiation with Montgomery reduction

Algebraic functions

OperationInputOutputAlgorithmComplexity
Polynomial evaluationOne polynomial of degree n with fixed-size coefficientsOne fixed-size numberDirect evaluationΘ
Polynomial evaluationOne polynomial of degree n with fixed-size coefficientsOne fixed-size numberHorner's methodΘ
Polynomial gcd Two polynomials of degree n with fixed-size integer coefficientsOne polynomial of degree at most nEuclidean algorithmO
Polynomial gcd Two polynomials of degree n with fixed-size integer coefficientsOne polynomial of degree at most nFast Euclidean algorithm O

Special functions

Many of the methods in this section are given in Borwein & Borwein.

Elementary functions

The elementary functions are constructed by composing arithmetic operations, the exponential function, the natural logarithm, trigonometric functions, and their inverses. The complexity of an elementary function is equivalent to that of its inverse, since all elementary functions are analytic and hence invertible by means of Newton's method. In particular, if either exp or log in the complex domain can be computed with some complexity, then that complexity is attainable for all other elementary functions.
Below, the size n refers to the number of digits of precision at which the function is to be evaluated.
AlgorithmApplicabilityComplexity
Taylor series; repeated argument reduction = exp and direct summationexp, log, sin, cos, arctanO
Taylor series; FFT-based accelerationexp, log, sin, cos, arctanO n1/3
Taylor series; [binary splitting + bit-burst algorithmexp, log, sin, cos, arctanO
Arithmetic–geometric mean iterationexp, log, sin, cos, arctanO

It is not known whether O is the optimal complexity for elementary functions. The best known lower bound is the trivial bound Ω.

Non-elementary functions

Mathematical constants

This table gives the complexity of computing approximations to the given constants to n correct digits.
ConstantAlgorithmComplexity
Golden ratio, φNewton's methodO
Square root of 2, Newton's methodO
Euler's number, eBinary splitting of the Taylor series for the exponential functionO
Euler's number, eNewton inversion of the natural logarithmO
Pi, πBinary splitting of the arctan series in Machin's formulaO
Pi, πGauss–Legendre algorithmO
Euler's constant, γSweeney's method O

Number theory

Algorithms for number theoretical calculations are studied in computational number theory.
OperationInputOutputAlgorithmComplexity
Greatest common divisorTwo n-digit integersOne integer with at most n digitsEuclidean algorithmO
Greatest common divisorTwo n-digit integersOne integer with at most n digitsBinary GCD algorithmO
Greatest common divisorTwo n-digit integersOne integer with at most n digitsLeft/right k-ary binary GCD algorithmO
Greatest common divisorTwo n-digit integersOne integer with at most n digitsStehlé–Zimmermann algorithmO
Greatest common divisorTwo n-digit integersOne integer with at most n digitsSchönhage controlled Euclidean descent algorithmO
Jacobi symbolTwo n-digit integers0, −1, or 1Schönhage controlled Euclidean descent algorithmO
Jacobi symbolTwo n-digit integers0, −1, or 1Stehlé–Zimmermann algorithmO
FactorialA positive integer less than mOne O-digit integerBottom-up multiplicationO
FactorialA positive integer less than mOne O-digit integerBinary splittingO
FactorialA positive integer less than mOne O-digit integerExponentiation of the prime factors of mO,
O
Primality testA n-digit integerTrue or falseAKS primality testO or,
O, assuming Agrawal's conjecture
Primality testA n-digit integerTrue or falseElliptic curve primality provingheuristically
Primality testA n-digit integerTrue or falseBaillie-PSW primality test
Primality testA n-digit integerTrue or falseMiller–Rabin primality test
Primality testA n-digit integerTrue or falseSolovay–Strassen primality test
Integer factorizationA b-bit input integerA set of factorsGeneral number field sieveO
Integer factorizationA b-bit input integerA set of factorsShor's algorithm, on a quantum computer

Matrix algebra

The following complexity figures assume that arithmetic with individual elements has complexity O, as is the case with fixed-precision floating-point arithmetic or operations on a finite field.
OperationInputOutputAlgorithmComplexity
Matrix multiplicationTwo n×n matricesOne n×n matrixSchoolbook matrix multiplicationO
Matrix multiplicationTwo n×n matricesOne n×n matrixStrassen algorithmO
Matrix multiplicationTwo n×n matricesOne n×n matrixCoppersmith–Winograd algorithmO
Matrix multiplicationTwo n×n matricesOne n×n matrixOptimized CW-like algorithmsO
Matrix multiplicationOne n×m matrix &
one m×p matrix
One n×p matrixSchoolbook matrix multiplicationO
Matrix multiplicationOne n×⌈n⌉ matrix &
one ⌈n⌉×n matrix
One n×n matrixAlgorithms given in, where upper bounds on are given in
Matrix inversionOne n×n matrixOne n×n matrixGauss–Jordan eliminationO
Matrix inversionOne n×n matrixOne n×n matrixStrassen algorithmO
Matrix inversionOne n×n matrixOne n×n matrixCoppersmith–Winograd algorithmO
Matrix inversionOne n×n matrixOne n×n matrixOptimized CW-like algorithmsO
Singular value decompositionOne m×n matrixOne m×m matrix,
one m×n matrix, &
one n×n matrix
Bidiagonalization and QR algorithmO
Singular value decompositionOne m×n matrixOne m×n matrix,
one n×n matrix, &
one n×n matrix
Bidiagonalization and QR algorithmO
DeterminantOne n×n matrixOne numberLaplace expansionO
DeterminantOne n×n matrixOne numberDivision-free algorithmO
DeterminantOne n×n matrixOne numberLU decompositionO
DeterminantOne n×n matrixOne numberBareiss algorithmO
DeterminantOne n×n matrixOne numberFast matrix multiplicationO
Back substitutionTriangular matrixn solutionsBack substitutionO

In 2005, Henry Cohn, Robert Kleinberg, Balázs Szegedy, and Chris Umans showed that either of two different conjectures would imply that the exponent of matrix multiplication is 2.
Because of the possibility of blockwise inverting a matrix, where an inversion of an matrix requires inversion of two half-sized matrices and six multiplications between two half-sized matrices, and since matrix multiplication has a lower bound of operations, it can be shown that a divide and conquer algorithm that uses blockwise inversion to invert a matrix runs with the same time complexity as the matrix multiplication algorithm that is used internally.

Transforms

Algorithms for computing transforms of functions are widely used in all areas of mathematics, particularly analysis and signal processing.
OperationInputOutputAlgorithmComplexity
Discrete Fourier transformFinite data sequence of size nSet of complex numbersFast Fourier transformO