<s>
HyperLogLog	B-Algorithm
is	O
an	O
algorithm	O
for	O
the	O
count-distinct	B-Algorithm
problem	I-Algorithm
,	O
approximating	O
the	O
number	O
of	O
distinct	O
elements	O
in	O
a	O
multiset	B-Language
.	O
</s>
<s>
Calculating	O
the	O
exact	O
cardinality	B-Application
of	O
the	O
distinct	O
elements	O
of	O
a	O
multiset	B-Language
requires	O
an	O
amount	O
of	O
memory	O
proportional	O
to	O
the	O
cardinality	B-Application
,	O
which	O
is	O
impractical	O
for	O
very	O
large	O
data	O
sets	O
.	O
</s>
<s>
Probabilistic	O
cardinality	B-Application
estimators	O
,	O
such	O
as	O
the	O
HyperLogLog	B-Algorithm
algorithm	O
,	O
use	O
significantly	O
less	O
memory	O
than	O
this	O
,	O
but	O
can	O
only	O
approximate	O
the	O
cardinality	B-Application
.	O
</s>
<s>
The	O
HyperLogLog	B-Algorithm
algorithm	O
is	O
able	O
to	O
estimate	O
cardinalities	B-Application
of>109	O
with	O
a	O
typical	O
accuracy	O
(	O
standard	O
error	O
)	O
of	O
2%	O
,	O
using	O
1.5kB	O
of	O
memory	O
.	O
</s>
<s>
HyperLogLog	B-Algorithm
is	O
an	O
extension	O
of	O
the	O
earlier	O
LogLog	O
algorithm	O
,	O
itself	O
deriving	O
from	O
the	O
1984	O
Flajolet	B-Algorithm
–	I-Algorithm
Martin	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
and	O
in	O
related	O
literature	O
on	O
the	O
count-distinct	B-Algorithm
problem	I-Algorithm
,	O
the	O
term	O
"	O
cardinality	B-Application
"	O
is	O
used	O
to	O
mean	O
the	O
number	O
of	O
distinct	O
elements	O
in	O
a	O
data	O
stream	O
with	O
repeated	O
elements	O
.	O
</s>
<s>
However	O
in	O
the	O
theory	O
of	O
multisets	B-Language
the	O
term	O
refers	O
to	O
the	O
sum	O
of	O
multiplicities	O
of	O
each	O
member	O
of	O
a	O
multiset	B-Language
.	O
</s>
<s>
The	O
basis	O
of	O
the	O
HyperLogLog	B-Algorithm
algorithm	O
is	O
the	O
observation	O
that	O
the	O
cardinality	B-Application
of	O
a	O
multiset	B-Language
of	O
uniformly	O
distributed	O
random	O
numbers	O
can	O
be	O
estimated	O
by	O
calculating	O
the	O
maximum	O
number	O
of	O
leading	O
zeros	O
in	O
the	O
binary	O
representation	O
of	O
each	O
number	O
in	O
the	O
set	O
.	O
</s>
<s>
In	O
the	O
HyperLogLog	B-Algorithm
algorithm	O
,	O
a	O
hash	B-Error_Name
function	I-Error_Name
is	O
applied	O
to	O
each	O
element	O
in	O
the	O
original	O
multiset	B-Language
to	O
obtain	O
a	O
multiset	B-Language
of	O
uniformly	O
distributed	O
random	O
numbers	O
with	O
the	O
same	O
cardinality	B-Application
as	O
the	O
original	O
multiset	B-Language
.	O
</s>
<s>
The	O
cardinality	B-Application
of	O
this	O
randomly	O
distributed	O
set	O
can	O
then	O
be	O
estimated	O
using	O
the	O
algorithm	O
above	O
.	O
</s>
<s>
The	O
simple	O
estimate	O
of	O
cardinality	B-Application
obtained	O
using	O
the	O
algorithm	O
above	O
has	O
the	O
disadvantage	O
of	O
a	O
large	O
variance	O
.	O
</s>
<s>
In	O
the	O
HyperLogLog	B-Algorithm
algorithm	O
,	O
the	O
variance	O
is	O
minimised	O
by	O
splitting	O
the	O
multiset	B-Language
into	O
numerous	O
subsets	O
,	O
calculating	O
the	O
maximum	O
number	O
of	O
leading	O
zeros	O
in	O
the	O
numbers	O
in	O
each	O
of	O
these	O
subsets	O
,	O
and	O
using	O
a	O
harmonic	O
mean	O
to	O
combine	O
these	O
estimates	O
for	O
each	O
subset	O
into	O
an	O
estimate	O
of	O
the	O
cardinality	B-Application
of	O
the	O
whole	O
set	O
.	O
</s>
<s>
The	O
HyperLogLog	B-Algorithm
has	O
three	O
main	O
operations	O
:	O
add	O
to	O
add	O
a	O
new	O
element	O
to	O
the	O
set	O
,	O
count	O
to	O
obtain	O
the	O
cardinality	B-Application
of	O
the	O
set	O
and	O
merge	O
to	O
obtain	O
the	O
union	O
of	O
two	O
sets	O
.	O
</s>
<s>
Some	O
derived	O
operations	O
can	O
be	O
computed	O
using	O
the	O
inclusion	O
–	O
exclusion	O
principle	O
like	O
the	O
cardinality	B-Application
of	O
the	O
intersection	O
or	O
the	O
cardinality	B-Application
of	O
the	O
difference	O
between	O
two	O
HyperLogLogs	B-Algorithm
combining	O
the	O
merge	O
and	O
count	O
operations	O
.	O
</s>
<s>
The	O
data	O
of	O
the	O
HyperLogLog	B-Algorithm
is	O
stored	O
in	O
an	O
array	O
of	O
counters	O
(	O
or	O
"	O
registers	O
"	O
)	O
that	O
are	O
initialized	O
to	O
0	O
.	O
</s>
<s>
Array	O
initialized	O
from	O
a	O
multiset	B-Language
is	O
called	O
HyperLogLog	B-Algorithm
sketch	O
of	O
S	O
.	O
</s>
<s>
The	O
add	O
operation	O
consists	O
of	O
computing	O
the	O
hash	B-Error_Name
of	O
the	O
input	O
data	O
with	O
a	O
hash	B-Error_Name
function	I-Error_Name
,	O
getting	O
the	O
first	O
bits	O
(	O
where	O
is	O
)	O
,	O
and	O
adding	O
1	O
to	O
them	O
to	O
obtain	O
the	O
address	O
of	O
the	O
register	O
to	O
modify	O
.	O
</s>
<s>
The	O
intuition	O
is	O
that	O
being	O
the	O
unknown	O
cardinality	B-Application
of	O
,	O
each	O
subset	O
will	O
have	O
elements	O
.	O
</s>
<s>
Finally	O
,	O
the	O
constant	O
is	O
introduced	O
to	O
correct	O
a	O
systematic	O
multiplicative	O
bias	O
present	O
in	O
due	O
to	O
hash	B-Error_Name
collisions	O
.	O
</s>
<s>
The	O
HyperLogLog	B-Algorithm
technique	O
,	O
though	O
,	O
is	O
biased	O
for	O
small	O
cardinalities	B-Application
below	O
a	O
threshold	O
of	O
.	O
</s>
<s>
The	O
original	O
paper	O
proposes	O
using	O
a	O
different	O
algorithm	O
for	O
small	O
cardinalities	B-Application
known	O
as	O
Linear	O
Counting	O
.	O
</s>
<s>
If	O
,	O
use	O
the	O
standard	O
HyperLogLog	B-Algorithm
estimator	O
above	O
.	O
</s>
<s>
Additionally	O
,	O
for	O
very	O
large	O
cardinalities	B-Application
approaching	O
the	O
limit	O
of	O
the	O
size	O
of	O
the	O
registers	O
(	O
for	O
32-bit	O
registers	O
)	O
,	O
the	O
cardinality	B-Application
can	O
be	O
estimated	O
with	O
:	O
</s>
<s>
The	O
relative	O
error	O
of	O
HLL	O
is	O
and	O
it	O
needs	O
space	O
,	O
where	O
is	O
the	O
set	O
cardinality	B-Application
and	O
is	O
the	O
number	O
of	O
registers	O
(	O
usually	O
less	O
than	O
one	O
byte	O
size	O
)	O
.	O
</s>
<s>
The	O
add	O
operation	O
depends	O
on	O
the	O
size	O
of	O
the	O
output	O
of	O
the	O
hash	B-Error_Name
function	I-Error_Name
.	O
</s>
<s>
In	O
some	O
implementations	O
(	O
Redis	B-Operating_System
)	O
the	O
number	O
of	O
registers	O
is	O
fixed	O
and	O
the	O
cost	O
is	O
considered	O
to	O
be	O
in	O
the	O
documentation	O
.	O
</s>
<s>
The	O
HyperLogLog++	O
algorithm	O
proposes	O
several	O
improvements	O
in	O
the	O
HyperLogLog	B-Algorithm
algorithm	O
to	O
reduce	O
memory	O
requirements	O
and	O
increase	O
accuracy	O
in	O
some	O
ranges	O
of	O
cardinalities	B-Application
:	O
</s>
<s>
64-bit	O
hash	B-Error_Name
function	I-Error_Name
is	O
used	O
instead	O
of	O
the	O
32	O
bits	O
used	O
in	O
the	O
original	O
paper	O
.	O
</s>
<s>
This	O
reduces	O
the	O
hash	B-Error_Name
collisions	O
for	O
large	O
cardinalities	B-Application
allowing	O
to	O
remove	O
the	O
large	O
range	O
correction	O
.	O
</s>
<s>
Some	O
bias	O
is	O
found	O
for	O
small	O
cardinalities	B-Application
when	O
switching	O
from	O
linear	O
counting	O
to	O
the	O
HLL	O
counting	O
.	O
</s>
<s>
A	O
sparse	O
representation	O
of	O
the	O
registers	O
is	O
proposed	O
to	O
reduce	O
memory	O
requirements	O
for	O
small	O
cardinalities	B-Application
,	O
which	O
can	O
be	O
later	O
transformed	O
to	O
a	O
dense	O
representation	O
if	O
the	O
cardinality	B-Application
grows	O
.	O
</s>
