encyclopegia.org

Count-distinct problem

In computer science, the count-distinct problem (also known in applied mathematics as the cardinality estimation problem) is the problem of finding the number of distinct elements in a data stream with repeated elements.[src] This is a well-known problem with numerous applications.[src] The elements might represent IP addresses of packets passing through a router, unique visitors to a web site, elements in a large database, motifs in a DNA sequence, or elements of RFID/sensor networks.[src]

In computer science, the count-distinct problem (also known in applied mathematics as the cardinality estimation problem) is the problem of finding the number of distinct elements in a data stream with repeated elements.[src] This is a well-known problem with numerous applications.[src] The elements might represent IP addresses of packets passing through a router, unique visitors to a web site, elements in a large database, motifs in a DNA sequence, or elements of RFID/sensor networks.[src] ==Formal definition== Instance: Consider a stream of elements x_1, x_2, \ldots, x_s with repetitions.[src] Let n denote the number of distinct elements in the stream, with the set of distinct elements represented as \{e_1, e_2, \ldots, e_n\} .[src] Objective: Find an estimate \widehat{n} of n using only m storage units, where m \ll n .[src] An example of an instance for the cardinality estimation problem is the stream: a,b,a,c,d,b,d .[src] For this instance, n = |\left\{ {a,b,c,d}\right\}| = 4 .[src] ==Naive solution== The naive solution to the problem is as follows: Initialize a counter, , to zero, Initialize an efficient dictionary data structure, , such as hash table or search tree in which insertion and membership can be performed quickly.[src] , a membership query is issued.[src] Increase by one, Otherwise do nothing.[src] As long as the number of distinct elements is not too big, fits in main memory and an exact answer can be retrieved.[src] However, this approach does not scale for bounded storage, or if the computation performed for each element x_i should be minimized.[src] In such a case, several streaming algorithms have been proposed that use a fixed number of storage units.[src] ==HyperLogLog algorithm== ==Streaming algorithms== To handle the bounded storage constraint, streaming algorithms use a randomization to produce a non-exact estimation of the distinct number of elements, n .[src] State-of-the-art estimators hash every element e_j into a low-dimensional data sketch using a hash function, h(e_j) .[src] The different techniques can be classified according to the data sketches they store.[src] ===Bottom-m sketches=== Bottom-m sketches are a generalization of min sketches, which maintain the m minimal values, where m \geq 1 .[src] See Cosma et al.[src] for a theoretical overview of count-distinct estimation algorithms, and Metwally for a practical overview with comparative simulation results.[src] def algorithm_d(stream, s: int): p = 1.0 buffer = {} for a in stream: if a in buffer: buffer.pop(a) u = uniform(0, 1) if u u_p: p = u else: buffer.pop(a_p) buffer[a] = u p = u_p return len(buffer) / p (a',u') such that u' = \max\{u:(a,u)\in B, \forall a\} /* (a',u') whose u' is maximum in */ If u > u' then p\leftarrow u else Replace (a',u') with (a_t, u) p\leftarrow u' The previous version of the CVM algorithm is improved with the following modification by Donald Knuth, that adds the while loop to ensure B is reduced.[src] Initialize max buffer size s , where s \geq 1 Initialize an empty buffer, in data stream A of size n do: Insert (a_t, u) into Remove every element of (a', u') of with u' > \frac{p}{2} If u then Insert (a_t, u) into ==Weighted count-distinct problem== In its weighted version, each element is associated with a weight and the goal is to estimate the total sum of weights.[src] Formally, Instance: A stream of weighted elements x_1,x_2,\ldots,x_s with repetitions, and an integer m .[src] Let n be the number of distinct elements, namely n = |\left\{ {x_1,x_2,\ldots,x_s}\right\}| , and let these elements be \left\{ {e_1,e_2,\ldots,e_n}\right\} .[src] Finally, let w_j be the weight of e_j .[src] Objective: Find an estimate \widehat{w} of w = \sum_{j=1}^{n}w_j using only m storage units, where m \ll n .[src] An example of an instance for the weighted problem is: a(3),b(4),a(3),c(2),d(3),b(4),d(3) .[src] For this instance, e_1=a, e_2=b, e_3=c, e_4=d , the weights are w_1=3, w_2=4, w_3=2, w_4=3 and \sum{w_j}=12 .[src] As an application example, x_1,x_2,\ldots,x_s could be IP packets received by a server.[src] Each packet belongs to one of n IP flows e_1,e_2,\ldots,e_n .[src] The weight w_j can be the load imposed by flow e_j on the server.[src] Thus, \sum_{j=1}^{n}{w_j} represents the total load imposed on the server by all the flows to which packets x_1,x_2,\ldots,x_s belong.[src] ==Solving the weighted count-distinct problem== Any extreme order statistics estimator (min/max sketches) for the unweighted problem can be generalized to an estimator for the weighted problem .[src] For example, the weighted estimator proposed by Cohen et al.[src] can be obtained when the continuous max sketches estimator is extended to solve the weighted problem.[src] In particular, the HyperLogLog algorithm can be extended to solve the weighted problem.[src] The extended HyperLogLog algorithm offers the best performance, in terms of statistical accuracy and memory usage, among all the other known algorithms for the weighted problem.[src] ==See also== Count–min sketch Streaming algorithm Maximum likelihood Minimum-variance unbiased estimator ==References==[src]

41 sentences · 41 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Count-distinct problem." encyclopegia.org, 2026, https://encyclopegia.org/wiki/count-distinct-problem. Accessed 27 November 2026.

Chicago

"Count-distinct problem." encyclopegia.org. Accessed November 27, 2026. https://encyclopegia.org/wiki/count-distinct-problem.

APA

encyclopegia.org. (2026). Count-distinct problem. Retrieved November 27, 2026, from https://encyclopegia.org/wiki/count-distinct-problem

Accessed November 27, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Joscelin I, Count of Edessa

stub · references available

Philip Louis, Count Palatine of Neuburg

stub · references available

Eberhard III, Count of Württemberg

stub · references available

Wolfgang, Count Palatine of Zweibrücken

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1368167218 · 0.5 · snapshot enwiki-001368167218

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.