# Why don't we use simple binary values to compress data?

In Huffman's algorithm, we form a tree and than replace each character with the tree value of 1 and 0. Why don't we simply use the binary digits like $a=0$, $b=1$, $c=10$, $d=01$, $e=11$ and so on than replace them with the characters and when decompressing aplly the reverse and replace the binary digits with the alphabets?

• There are definitely many possible codes. – Raphael Apr 8 '15 at 10:54
• Have you looked at en.wikipedia.org/wiki/Huffman_coding? You have to read a bit if you want to understand. The first sentance says: a Huffman code is an optimal prefix code. What does it mean, and why is it important? – babou Apr 8 '15 at 10:55

Suppose we code, as you suggest, $a=0$, $b=1$, $c=10$, $d=01$, $e=11$, etc., and I send you the message $1001$. You can't tell if I said $10\,0\,1=cab$, $1\,0\,01=bad$. The point of the Huffman scheme is that it's a prefix code, so it's uniquely decodable (and, further, you can always decode the start of the message based on the bits you've already seen, without having to look into the future).