Algorithm Search⌘K

Definitionintro

Polylogarithmic time

Also called polylog time.

Running time bounded by a polynomial in log n.

An algorithm runs in polylogarithmic time when its worst-case time is O((log⁡n)k)O((\log n)^k) for some constant kk, where nn is the input size. The class contains constant time and logarithmic time, which are the cases k=0k = 0 and k=1k = 1. It is a subclass of sublinear time: a power of a logarithm grows more slowly than each power nεn^{\varepsilon} with ε>0\varepsilon > 0. It appears in the query time of data structures and in the parallel time of the class NC.

Definition

Let ff be a function from the natural numbers to the non-negative reals. The function ff is polylogarithmic when there are constants k≥0k \ge 0, c>0c > 0 and n0≥2n_0 \ge 2 such that

∀n≥n0: f(n)≤c (lg⁡n)k.\forall n \ge n_0 : \ f(n) \le c\,(\lg n)^k.

In words, f(n)=O((log⁡n)k)f(n) = O((\log n)^k) for some constant kk. The threshold n0≥2n_0 \ge 2 keeps lg⁡n\lg n positive. An algorithm runs in polylogarithmic time when its worst-case time in a stated model is a polylogarithmic function of the input size.

A polylogarithmic-time algorithm reads only a tiny part of its input, so the model must give random access to the input, for example the random-access machine or a Turing machine with random access. A machine with a sequential tape needs nn steps just to reach the end of its input. For a data structure, nn is the number of stored items: the query time is polylogarithmic in nn after a preprocessing that reads all nn items.

The class is the union over kk of the classes O((log⁡n)k)O((\log n)^k), and each class is contained in the next one, since (lg⁡n)k≤(lg⁡n)k+1(\lg n)^k \le (\lg n)^{k+1} for n≥2n \ge 2. A real kk gives the same union as an integer kk, because (lg⁡n)k≤(lg⁡n)⌈k⌉(\lg n)^k \le (\lg n)^{\lceil k \rceil}.

The base does not matter. For bases a,b>1a, b > 1, log⁡an=log⁡bn/log⁡ba\log_a n = \log_b n / \log_b a, so (log⁡an)k=(log⁡bn)k/(log⁡ba)k(\log_a n)^k = (\log_b n)^k / (\log_b a)^k, which differs from (log⁡bn)k(\log_b n)^k by a constant factor. So O((log⁡an)k)=O((log⁡bn)k)O((\log_a n)^k) = O((\log_b n)^k), and the base needs no mention inside OO. See logarithms.

Notation. The expression lg⁡kn\lg^k n means (lg⁡n)k(\lg n)^k, the kk-th power of the logarithm. It does not mean that the logarithm is applied kk times. That function is the iterated logarithm lg⁡(k)n\lg^{(k)} n with the number kk in parentheses, see iterated logarithm. Also log⁡(nk)=klog⁡n\log(n^k) = k \log n is Θ(log⁡n)\Theta(\log n), and it is not (log⁡n)k(\log n)^k. For n=220n = 2^{20} we have lg⁡2n=400\lg^2 n = 400, lg⁡(n2)=40\lg(n^2) = 40 and lg⁡lg⁡n=lg⁡20≈4.32\lg \lg n = \lg 20 \approx 4.32. The function lg⁡lg⁡n\lg \lg n is polylogarithmic, since lg⁡lg⁡n≤lg⁡n\lg \lg n \le \lg n for n≥2n \ge 2.

Order. For each constant kk and ε>0\varepsilon > 0, (lg⁡n)k=o(nε)(\lg n)^k = o(n^{\varepsilon}), see asymptotic notation. To see this, put n=2mn = 2^m. Then (lg⁡n)k/nε=mk/2εm(\lg n)^k / n^{\varepsilon} = m^k / 2^{\varepsilon m}, and this tends to 0 as m→∞m \to \infty, because an exponential function beats each power of mm. The class O((log⁡n)k)O((\log n)^k) is strictly inside O((log⁡n)k+1)O((\log n)^{k+1}), because (lg⁡n)k+1/(lg⁡n)k=lg⁡n→∞(\lg n)^{k+1} / (\lg n)^k = \lg n \to \infty. So a polylogarithmic function is o(nε)o(n^{\varepsilon}) for every ε\varepsilon, and it is sublinear.

The soft-O notation hides polylogarithmic factors: O~(f(n))\tilde O(f(n)) means O(f(n)(log⁡n)k)O(f(n) (\log n)^k) for some constant kk. For example, an O(nlog⁡2n)O(n \log^2 n) time is O~(n)\tilde O(n).

Examples and non-examples

  • Binary search in a sorted array takes at most ⌊lg⁡n⌋+1\lfloor \lg n \rfloor + 1 comparisons. This is Θ(log⁡n)\Theta(\log n), so k=1k = 1. For n=106n = 10^6 it is 20. See binary search.
  • Search trees and heaps. A search, an insertion or a deletion in a balanced search tree such as an AVL tree takes O(log⁡n)O(\log n) time, and the insertion in a binary heap takes O(log⁡n)O(\log n) time, where nn is the number of stored items.
  • Range queries. A segment tree or a Fenwick tree answers a range-sum query and takes a point update in O(log⁡n)O(\log n) time, after a preprocessing of O(n)O(n) time, where nn is the number of stored items.
  • A power of the logarithm. A structure with query time O(log⁡2n)O(\log^2 n) is polylogarithmic with k=2k = 2. Some structures for range queries in the plane have a query time of this form, where nn is the number of stored points.
  • Parallel time. The sum of nn numbers takes ⌈lg⁡n⌉\lceil \lg n \rceil rounds when each round adds the numbers in pairs, in parallel, with ⌊n/2⌋\lfloor n/2 \rfloor processors in the first round. The parallel time is O(log⁡n)O(\log n) while the work is Θ(n)\Theta(n).
  • Non-example: n\sqrt{n}, or nεn^{\varepsilon} for a constant ε>0\varepsilon > 0. These are sublinear and not polylogarithmic.
  • Non-example: n/log⁡nn / \log n is sublinear. It is not polylogarithmic, because it is not bounded by c(lg⁡n)kc (\lg n)^k for any kk.
  • Non-example: (lg⁡n)lg⁡n=nlg⁡lg⁡n(\lg n)^{\lg n} = n^{\lg \lg n} grows faster than each (lg⁡n)k(\lg n)^k, since for n>2k+1n > 2^{k+1} the ratio (lg⁡n)lg⁡n/(lg⁡n)k=(lg⁡n)lg⁡n−k(\lg n)^{\lg n} / (\lg n)^k = (\lg n)^{\lg n - k} is at least lg⁡n\lg n, which grows without bound. It is quasi-polynomial, see quasi-polynomial time.
  • Non-example: 2lg⁡n2^{\sqrt{\lg n}} is not polylogarithmic. Its logarithm is lg⁡n\sqrt{\lg n}, and the logarithm of c(lg⁡n)kc(\lg n)^k is lg⁡c+klg⁡lg⁡n\lg c + k \lg \lg n, which grows more slowly.
  • Non-example: a time that is Θ(log⁡N)\Theta(\log N) in the value NN of the input is linear in the length b≈lg⁡Nb \approx \lg N of the input. The input size of an integer NN is b≈lg⁡Nb \approx \lg N bits, so a time of log⁡N\log N steps is Θ(b)\Theta(b) and not polylogarithmic in bb. Fast exponentiation takes O(log⁡e)O(\log e) multiplications for the exponent ee, which is linear in the number of bits of ee.

A polylogarithm is not small for a small input

Constants and exponents matter for the input sizes of practice. At n=216=65536n = 2^{16} = 65536, lg⁡2n=256=n\lg^2 n = 256 = \sqrt n. Let ℓ=lg⁡n\ell = \lg n. Then n/lg⁡2n=2ℓ/2/ℓ2\sqrt{n} / \lg^2 n = 2^{\ell/2} / \ell^2, and the logarithm of this ratio increases when ℓ>4/ln⁡2≈5.77\ell > 4/\ln 2 \approx 5.77. The ratio is 1 at ℓ=16\ell = 16, so lg⁡2n<n\lg^2 n < \sqrt n for each n>216n > 2^{16}. For n=220n = 2^{20} the values are lg⁡n=20\lg n = 20, lg⁡2n=400\lg^2 n = 400, lg⁡3n=8000\lg^3 n = 8000 and n=1024\sqrt n = 1024, so lg⁡3n\lg^3 n is still larger than n\sqrt n. Asymptotic notation says nothing about a fixed nn.

  • Constant time is O(1)O(1), the case k=0k = 0. Logarithmic time is O(log⁡n)O(\log n), the case k=1k = 1.
  • Sublinear time is o(n)o(n) and contains polylogarithmic time. Polynomial time is O(nk)O(n^k) and contains it too.
  • The class NC\mathrm{NC} is the set of problems that are solvable in polylogarithmic parallel time with polynomially many processors, in the following circuit form. For k≥1k \ge 1, NCk\mathrm{NC}^k is the class of decision problems that uniform families of Boolean circuits decide, with fan-in 2, size polynomial in nn and depth O((log⁡n)k)O((\log n)^k). The class NC\mathrm{NC} is the union of NCk\mathrm{NC}^k over kk. It is contained in P. It is open whether the two are equal. See NC and the class P in polynomial time.
  • Common growth rates places the polylogarithmic functions between the constants and the powers of nn.

References

  1. https://en.wikipedia.org/wiki/Time_complexity, section Polylogarithmic time
  2. Cormen, Leiserson, Rivest and Stein, Introduction to Algorithms, fourth edition, Chapter 3 (standard notations, polylogarithmically bounded functions)
  3. Donald E. Knuth, The Art of Computer Programming, Volume 1, third edition, Section 1.2.11.1
  4. Arora and Barak, Computational Complexity, A Modern Approach, Chapter 6 (the class NC)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/40MSAP/text.yaml