0
$\begingroup$

enter image description here

I'm trying to code a simple string abbcccad. I started with:

  1. Computing the "valor" of each letter.
  2. Ordering them by their valor.
  3. Adding the last 2 of them until I get the last 2 that added will be 1.

Please correct me if I saied something wrong until now.

Where I'm stucked, is how do I get the final code now?

$\endgroup$

1 Answer 1

0
$\begingroup$

Your way of drawing the tree is somewhat confusing. The way to obtain the code word is to travel from the final node (i.e. the node at the end, where 0.375 and 0.625 sum up to 1) to the leaf of the desired symbol. Then, if you encounter a top branch, you write 0 and if you encounter a bottom branch, you write 1 (or the other way around, as long as you are consistent).

For instance, to code $d$, you go through an upper branch and then a lower branch, so $d\rightarrow 01$. For $b$ you get $b\rightarrow 00$.

To check that everything it in order, you can verify that it is a prefix code. I.e., that if you write the code words right next to each other, you can always decipher them back without ambiguity.

$\endgroup$
1
  • $\begingroup$ I think that I got it. Can you confirm that the result is 1001011111111000 ? $\endgroup$
    – user140102
    Commented May 29, 2014 at 12:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .