<s>
In	O
the	O
field	O
of	O
data	B-General_Concept
compression	I-General_Concept
,	O
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
coding	I-Algorithm
,	O
named	O
after	O
Claude	O
Shannon	O
and	O
Robert	O
Fano	O
,	O
is	O
a	O
name	O
given	O
to	O
two	O
different	O
but	O
related	O
techniques	O
for	O
constructing	O
a	O
prefix	B-Algorithm
code	I-Algorithm
based	O
on	O
a	O
set	O
of	O
symbols	O
and	O
their	O
probabilities	O
(	O
estimated	O
or	O
measured	O
)	O
.	O
</s>
<s>
Shannon	O
's	O
method	O
chooses	O
a	O
prefix	B-Algorithm
code	I-Algorithm
where	O
a	O
source	O
symbol	O
is	O
given	O
the	O
codeword	O
length	O
.	O
</s>
<s>
Shannon	O
–	O
Fano	O
codes	O
are	O
suboptimal	O
in	O
the	O
sense	O
that	O
they	O
do	O
not	O
always	O
achieve	O
the	O
lowest	O
possible	O
expected	O
codeword	O
length	O
,	O
as	O
Huffman	B-General_Concept
coding	I-General_Concept
does	O
.	O
</s>
<s>
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
coding	I-Algorithm
should	O
not	O
be	O
confused	O
with	O
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
–	I-Algorithm
Elias	I-Algorithm
coding	I-Algorithm
(	O
also	O
known	O
as	O
Elias	O
coding	O
)	O
,	O
the	O
precursor	O
to	O
arithmetic	B-Algorithm
coding	I-Algorithm
.	O
</s>
<s>
Around	O
1948	O
,	O
both	O
Claude	O
E	O
.	O
Shannon	O
(	O
1948	O
)	O
and	O
Robert	O
M	O
.	O
Fano	O
(	O
1949	O
)	O
independently	O
proposed	O
two	O
different	O
source	B-General_Concept
coding	I-General_Concept
algorithms	O
for	O
an	O
efficient	O
description	O
of	O
a	O
discrete	O
memoryless	O
source	O
.	O
</s>
<s>
Unfortunately	O
,	O
in	O
spite	O
of	O
being	O
different	O
,	O
both	O
schemes	O
became	O
known	O
under	O
the	O
same	O
name	O
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
coding	I-Algorithm
.	O
</s>
<s>
Shannon	O
's	O
(	O
1948	O
)	O
method	O
,	O
using	O
predefined	O
word	O
lengths	O
,	O
is	O
called	O
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
coding	I-Algorithm
by	O
Cover	O
and	O
Thomas	O
,	O
Goldie	O
and	O
Pinch	O
,	O
Jones	O
and	O
Jones	O
,	O
and	O
Han	O
and	O
Kobayashi	O
.	O
</s>
<s>
Fano	O
's	O
(	O
1949	O
)	O
method	O
,	O
using	O
binary	O
division	O
of	O
probabilities	O
,	O
is	O
called	O
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
coding	I-Algorithm
by	O
Salomon	O
and	O
Gupta	O
.	O
</s>
<s>
Shannon	O
's	O
method	O
starts	O
by	O
deciding	O
on	O
the	O
lengths	O
of	O
all	O
the	O
codewords	O
,	O
then	O
picks	O
a	O
prefix	B-Algorithm
code	I-Algorithm
with	O
those	O
word	O
lengths	O
.	O
</s>
<s>
Here	O
,	O
is	O
the	O
entropy	O
,	O
and	O
Shannon	B-Protocol
's	I-Protocol
source	I-Protocol
coding	I-Protocol
theorem	I-Protocol
says	O
that	O
any	O
code	O
must	O
have	O
an	O
average	O
length	O
of	O
at	O
least	O
.	O
</s>
<s>
Unfortunately	O
,	O
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
coding	I-Algorithm
does	O
not	O
always	O
produce	O
optimal	O
prefix	B-Algorithm
codes	I-Algorithm
;	O
the	O
set	O
of	O
probabilities	O
{	O
0.35	O
,	O
0.17	O
,	O
0.17	O
,	O
0.16	O
,	O
0.15	O
}	O
is	O
an	O
example	O
of	O
one	O
that	O
will	O
be	O
assigned	O
non-optimal	O
codes	O
by	O
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
coding	I-Algorithm
.	O
</s>
<s>
Fano	O
's	O
version	O
of	O
Shannon	B-Algorithm
–	I-Algorithm
Fano	I-Algorithm
coding	I-Algorithm
is	O
used	O
in	O
the	O
IMPLODE	O
compression	O
method	O
,	O
which	O
is	O
part	O
of	O
the	O
ZIP	B-General_Concept
file	I-General_Concept
format	I-General_Concept
.	O
</s>
<s>
For	O
this	O
reason	O
,	O
Shannon	O
–	O
Fano	O
codes	O
are	O
almost	O
never	O
used	O
;	O
Huffman	B-General_Concept
coding	I-General_Concept
is	O
almost	O
as	O
computationally	O
simple	O
and	O
produces	O
prefix	B-Algorithm
codes	I-Algorithm
that	O
always	O
achieve	O
the	O
lowest	O
possible	O
expected	O
code	O
word	O
length	O
,	O
under	O
the	O
constraints	O
that	O
each	O
symbol	O
is	O
represented	O
by	O
a	O
code	O
formed	O
of	O
an	O
integral	O
number	O
of	O
bits	O
.	O
</s>
<s>
If	O
we	O
consider	O
groups	O
of	O
codes	O
at	O
a	O
time	O
,	O
symbol-by-symbol	O
Huffman	B-General_Concept
coding	I-General_Concept
is	O
only	O
optimal	O
if	O
the	O
probabilities	O
of	O
the	O
symbols	O
are	O
independent	O
and	O
are	O
some	O
power	O
of	O
a	O
half	O
,	O
i.e.	O
,	O
.	O
</s>
<s>
In	O
most	O
situations	O
,	O
arithmetic	B-Algorithm
coding	I-Algorithm
can	O
produce	O
greater	O
overall	O
compression	O
than	O
either	O
Huffman	O
or	O
Shannon	O
–	O
Fano	O
,	O
since	O
it	O
can	O
encode	O
in	O
fractional	O
numbers	O
of	O
bits	O
which	O
more	O
closely	O
approximate	O
the	O
actual	O
information	O
content	O
of	O
the	O
symbol	O
.	O
</s>
<s>
However	O
,	O
arithmetic	B-Algorithm
coding	I-Algorithm
has	O
not	O
superseded	O
Huffman	O
the	O
way	O
that	O
Huffman	O
supersedes	O
Shannon	O
–	O
Fano	O
,	O
both	O
because	O
arithmetic	B-Algorithm
coding	I-Algorithm
is	O
more	O
computationally	O
expensive	O
and	O
because	O
it	O
is	O
covered	O
by	O
multiple	O
patents	O
.	O
</s>
<s>
While	O
Fano	O
's	O
Shannon	O
–	O
Fano	O
tree	O
is	O
created	O
by	O
dividing	O
from	O
the	O
root	O
to	O
the	O
leaves	O
,	O
the	O
Huffman	B-General_Concept
algorithm	I-General_Concept
works	O
in	O
the	O
opposite	O
direction	O
,	O
merging	O
from	O
the	O
leaves	O
to	O
the	O
root	O
.	O
</s>
<s>
Create	O
a	O
leaf	O
node	O
for	O
each	O
symbol	O
and	O
add	O
it	O
to	O
a	O
priority	B-Application
queue	I-Application
,	O
using	O
its	O
frequency	O
of	O
occurrence	O
as	O
the	O
priority	O
.	O
</s>
<s>
We	O
see	O
that	O
the	O
Huffman	B-General_Concept
code	I-General_Concept
has	O
outperformed	O
both	O
types	O
of	O
Shannon	O
–	O
Fano	O
code	O
,	O
which	O
had	O
expected	O
lengths	O
of	O
2.62	O
and	O
2.28	O
.	O
</s>
