2
$\begingroup$

When we are constructing the Huffman tree to get the Huffman codes, Is it possible to give "1" to left side and "0" to right side rather than giving "0" to left side and "1" to right side of the tree?

$\endgroup$
2
$\begingroup$

You can assign the $1$ and $0$ as you like, but be consistent. Only your code change, i.e. a 1011 becomes a 0100.

$\endgroup$
  • $\begingroup$ when we are decoding how can we identify which method used for the encoding(0-left method or 0-right method).? $\endgroup$ – dulaj sanjaya Jul 10 '16 at 13:22
  • $\begingroup$ From the codeword itself you cannot determine the assignment. You need to look into the implementation itself. Most implementations however assign the left-child a $0$ and the right-child a $1$. $\endgroup$ – dtt Jul 10 '16 at 13:39
2
$\begingroup$

Yes, You can.
But you'll need the Huffman tree to decode since the placing of left child and right child is arbitrary. If you're given an encoded string and ask you to decode, you can't do that since you don't know the exact algorithm which is used in building the Huffman Tree.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.