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, below stands in for the complexity of the chosen multiplication algorithm.

Arithmetic functions

This table lists the complexity of mathematical operations on integers.
OperationInputOutputAlgorithmComplexity
AdditionTwo -digit numbersOne -digit numberSchoolbook addition with carry
SubtractionTwo -digit numbersOne -digit numberSchoolbook subtraction with borrow
MultiplicationTwo -digit numbers
One -digit numberSchoolbook long multiplication
MultiplicationTwo -digit numbers
One -digit numberKaratsuba algorithm
MultiplicationTwo -digit numbers
One -digit number3-way Toom–Cook multiplication
MultiplicationTwo -digit numbers
One -digit number-
MultiplicationTwo -digit numbers
One -digit numberMixed-level Toom–Cook
MultiplicationTwo -digit numbers
One -digit numberSchönhage–Strassen algorithm
MultiplicationTwo -digit numbers
One -digit numberHarvey-Hoeven algorithm
DivisionTwo -digit numbersOne -digit numberSchoolbook long division
DivisionTwo -digit numbersOne -digit numberBurnikel–Ziegler Divide-and-Conquer Division
DivisionTwo -digit numbersOne -digit numberNewton–Raphson division
Square rootOne -digit numberOne -digit numberNewton's method
Modular exponentiationTwo -digit integers and a -bit exponentOne -digit integerRepeated multiplication and reduction
Modular exponentiationTwo -digit integers and a -bit exponentOne -digit integerExponentiation by squaring
Modular exponentiationTwo -digit integers and a -bit exponentOne -digit integerExponentiation with Montgomery reduction

On stronger computational models, specifically a pointer machine and consequently also a unit-cost random-access machine it is possible to multiply two -bit numbers in time O.

Algebraic functions

Here we consider operations over polynomials and denotes their degree; for the coefficients we use a unit-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.
OperationInputOutputAlgorithmComplexity
Polynomial evaluationOne polynomial of degree with integer coefficientsOne numberDirect evaluation
Polynomial evaluationOne polynomial of degree with integer coefficientsOne numberHorner's method
Polynomial multipoint evaluationOne polynomial of degree less than with integer coefficients and numbers as evaluation pointsnumbersDirect evaluation
Polynomial multipoint evaluationOne polynomial of degree less than with integer coefficients and numbers as evaluation pointsnumbersFast multipoint evaluation
Polynomial gcd Two polynomials of degree with integer coefficientsOne polynomial of degree at mostEuclidean algorithm
Polynomial gcd Two polynomials of degree with integer coefficientsOne polynomial of degree at mostFast Euclidean algorithm

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 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.
AlgorithmApplicabilityComplexity
Taylor series; repeated argument reduction and direct summation
Taylor series; FFT-based acceleration
Taylor series; binary splitting + bit-burst algorithm
Arithmetic–geometric mean iteration

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

Mathematical constants

This table gives the complexity of computing approximations to the given constants to correct digits.
ConstantAlgorithmComplexity
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
Euler's number,Newton inversion of the natural logarithm
Pi,Binary splitting of the arctan series in Machin's formula
Pi,Gauss–Legendre algorithm
Euler's constant,Sweeney's method

Number theory

Algorithms for number theoretical calculations are studied in computational number theory.
OperationInputOutputAlgorithmComplexity
Greatest common divisorTwo -digit integersOne integer with at most digitsEuclidean algorithm
Greatest common divisorTwo -digit integersOne integer with at most digitsBinary GCD algorithm
Greatest common divisorTwo -digit integersOne integer with at most digitsLeft/right k-ary binary GCD algorithm
Greatest common divisorTwo -digit integersOne integer with at most digitsStehlé–Zimmermann algorithm
Greatest common divisorTwo -digit integersOne integer with at most digitsSchönhage controlled Euclidean descent algorithm
Jacobi symbolTwo -digit integers, orSchönhage controlled Euclidean descent algorithm
Jacobi symbolTwo -digit integers, orStehlé–Zimmermann algorithm
FactorialA positive integer less thanOne -digit integerBottom-up multiplication
FactorialA positive integer less thanOne -digit integerBinary splitting
FactorialA positive integer less thanOne -digit integerExponentiation of the prime factors of,
Primality testA -digit integerTrue or falseAKS primality test
, assuming Agrawal's conjecture
Primality testA -digit integerTrue or falseElliptic curve primality provingheuristically
Primality testA -digit integerTrue or falseBaillie–PSW primality test
Primality testA -digit integerTrue or falseMiller–Rabin primality test
Primality testA -digit integerTrue or falseSolovay–Strassen primality test
Integer factorizationA -bit input integerA set of factorsGeneral number field sieve
Integer factorizationA -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 matricesOne matrixSchoolbook matrix multiplication
Matrix multiplicationTwo matricesOne matrixStrassen algorithm
Matrix multiplicationTwo matricesOne matrixCoppersmith–Winograd algorithm
Matrix multiplicationTwo matricesOne matrixOptimized CW-like algorithms
Matrix multiplicationOne matrix, and
one matrix
One matrixSchoolbook matrix multiplication
Matrix multiplicationOne matrix, and
one matrix, for some
One matrixAlgorithms given in, where upper bounds on are given in
Matrix inversionOne matrixOne matrixGauss–Jordan elimination
Matrix inversionOne matrixOne matrixStrassen algorithm
Matrix inversionOne matrixOne matrixCoppersmith–Winograd algorithm
Matrix inversionOne matrixOne matrixOptimized CW-like algorithms
Singular value decompositionOne matrixOne matrix,
one matrix, &
one matrix
Bidiagonalization and QR algorithm
Singular value decompositionOne matrixOne matrix,
one matrix, &
one matrix
Bidiagonalization and QR algorithm
QR decompositionOne matrixOne matrix, &
one matrix
Algorithms in
DeterminantOne matrixOne numberLaplace expansion
DeterminantOne matrixOne numberDivision-free algorithm
DeterminantOne matrixOne numberLU decomposition
DeterminantOne matrixOne numberBareiss algorithm
DeterminantOne matrixOne numberFast matrix multiplication
Back substitutionTriangular matrixsolutionsBack substitution
Characteristic polynomialOne matrixOne degree- polynomialFaddeev-LeVerrier algorithm
Characteristic polynomialOne matrixOne degree- polynomialSamuelson-Berkowitz algorithm
Characteristic polynomialOne matrixOne degree- polynomialPreparata-Sarwate algorithm

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.

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 sizeSet of complex numbersSchoolbook
Discrete Fourier transformFinite data sequence of sizeSet of complex numbersFast Fourier transform