<s>
The	O
Flajolet	B-Algorithm
–	I-Algorithm
Martin	I-Algorithm
algorithm	I-Algorithm
is	O
an	O
algorithm	O
for	O
approximating	O
the	O
number	O
of	O
distinct	O
elements	O
in	O
a	O
stream	O
with	O
a	O
single	O
pass	O
and	O
space-consumption	O
logarithmic	O
in	O
the	O
maximal	O
number	O
of	O
possible	O
distinct	O
elements	O
in	O
the	O
stream	O
(	O
the	O
count-distinct	B-Algorithm
problem	I-Algorithm
)	O
.	O
</s>
<s>
The	O
algorithm	O
was	O
introduced	O
by	O
Philippe	O
Flajolet	O
and	O
G	O
.	O
Nigel	O
Martin	O
in	O
their	O
1984	O
article	O
"	O
Probabilistic	B-Algorithm
Counting	I-Algorithm
Algorithms	O
for	O
Data	O
Base	O
Applications	O
"	O
.	O
</s>
<s>
Later	O
it	O
has	O
been	O
refined	O
in	O
"	O
LogLog	O
counting	O
of	O
large	O
cardinalities	O
"	O
by	O
Marianne	O
Durand	O
and	O
Philippe	O
Flajolet	O
,	O
and	O
"	O
HyperLogLog	B-Algorithm
:	O
The	O
analysis	O
of	O
a	O
near-optimal	O
cardinality	B-Algorithm
estimation	I-Algorithm
algorithm	O
"	O
by	O
Philippe	O
Flajolet	O
et	O
al	O
.	O
</s>
<s>
Assume	O
that	O
we	O
are	O
given	O
a	O
hash	B-Error_Name
function	I-Error_Name
that	O
maps	O
input	O
to	O
integers	O
in	O
the	O
range	O
,	O
and	O
where	O
the	O
outputs	O
are	O
sufficiently	O
uniformly	O
distributed	O
.	O
</s>
<s>
At	O
this	O
point	O
,	O
note	O
that	O
under	O
the	O
assumption	O
that	O
the	O
output	O
of	O
our	O
hash	B-Error_Name
function	I-Error_Name
is	O
uniformly	O
distributed	O
,	O
then	O
the	O
probability	O
of	O
observing	O
a	O
hash	B-Error_Name
output	O
ending	O
with	O
(	O
a	O
one	O
,	O
followed	O
by	O
zeroes	O
)	O
is	O
,	O
since	O
this	O
corresponds	O
to	O
flipping	O
heads	O
and	O
then	O
a	O
tail	O
with	O
a	O
fair	O
coin	O
.	O
</s>
<s>
Now	O
the	O
Flajolet	B-Algorithm
–	I-Algorithm
Martin	I-Algorithm
algorithm	I-Algorithm
for	O
estimating	O
the	O
cardinality	O
of	O
a	O
multiset	B-Language
is	O
as	O
follows	O
:	O
</s>
<s>
The	O
idea	O
is	O
that	O
if	O
is	O
the	O
number	O
of	O
distinct	O
elements	O
in	O
the	O
multiset	B-Language
,	O
then	O
is	O
accessed	O
approximately	O
times	O
,	O
is	O
accessed	O
approximately	O
times	O
and	O
so	O
on	O
.	O
</s>
<s>
A	O
problem	O
with	O
the	O
Flajolet	B-Algorithm
–	I-Algorithm
Martin	I-Algorithm
algorithm	I-Algorithm
in	O
the	O
above	O
form	O
is	O
that	O
the	O
results	O
vary	O
significantly	O
.	O
</s>
<s>
A	O
common	O
solution	O
has	O
been	O
to	O
run	O
the	O
algorithm	O
multiple	O
times	O
with	O
different	O
hash	B-Error_Name
functions	I-Error_Name
and	O
combine	O
the	O
results	O
from	O
the	O
different	O
runs	O
.	O
</s>
<s>
One	O
idea	O
is	O
to	O
take	O
the	O
mean	O
of	O
the	O
results	O
together	O
from	O
each	O
hash	B-Error_Name
function	I-Error_Name
,	O
obtaining	O
a	O
single	O
estimate	O
of	O
the	O
cardinality	O
.	O
</s>
<s>
A	O
common	O
solution	O
is	O
to	O
combine	O
both	O
the	O
mean	O
and	O
the	O
median	O
:	O
Create	O
hash	B-Error_Name
functions	I-Error_Name
and	O
split	O
them	O
into	O
distinct	O
groups	O
(	O
each	O
of	O
size	O
)	O
.	O
</s>
<s>
The	O
2007	O
HyperLogLog	B-Algorithm
algorithm	O
splits	O
the	O
multiset	B-Language
into	O
subsets	O
and	O
estimates	O
their	O
cardinalities	O
,	O
then	O
it	O
uses	O
the	O
harmonic	O
mean	O
to	O
combine	O
them	O
into	O
an	O
estimate	O
for	O
the	O
original	O
cardinality	O
.	O
</s>
