# Binary Tree and Variable Length Codes for given Alphabets using Huffman Encoding (Confusion)

Last week our teacher gave us a question about Huffman Encoding Algorithm described as below.

HUFFMAN ENCODING ALGORITHM:

1. Consider all pairs: .
2. Choose the two lowest frequencies, and make them brothers, with the root having the combined frequency.
3. Iterate.

The question was to find the `Final Binary Tree` and `Variable Length Codes` for the given Alphabets using the above defined Huffman Encoding Algorithm:

`A | 10`

`B | 20`

`C | 30`

`D | 40`

`E | 50`

`F | 60`

I solved the question but my teacher said that I made the wrong tree. Kindly check my answer below and tell me where I am wrong?

Final Binary Tree:

Variable Length Code:

Kindly tell me where I am wrong? What wrong I did while making the above Binary Tree?

You did this once for `A=10, B=20` for a total of 30, right?
Next you picked `C=30, D=40` for a total 70. But there was a better choice, as there are two nodes with score of 30 for a total of only 60. One of them is `C=30`, and the other? Well, think more dynamically.