MHB How Do You Calculate the Total Weight of a Huffman Code?

  • Thread starter Thread starter mathmari
  • Start date Start date
  • Tags Tags
    Code Weight
Click For Summary
To calculate the total weight of a Huffman code, determine the weighted path length from the root of the Huffman tree. This involves multiplying the length of each symbol's code by its frequency and summing these products. For example, the contribution of the letter 'a' is calculated as its code length (4) multiplied by its frequency (2), resulting in a total of 8. There is a suggestion that the initial Huffman tree may not be optimal, as another tree configuration could yield a lower total weight. Understanding these calculations is essential for achieving optimal data compression.
mathmari
Gold Member
MHB
Messages
4,984
Reaction score
7
Hey! 😊

We are given the following letters with the respective frequencies:
\begin{equation*}\begin{matrix}a/2 & b/4 & c/7 & d/6 & e/4 & f/5 & g/8 & h/10 & i/3 & j/11\end{matrix}\end{equation*}

For that I have applied the Huffman code and I got the following tree:

Huffman.JPG
Now it is asked for the total weight of the code. How do we calculate that? :unsure:
 
Physics news on Phys.org
mathmari said:
We are given the following letters with the respective frequencies:
\begin{equation*}\begin{matrix}a/2 & b/4 & c/7 & d/6 & e/4 & f/5 & g/8 & h/10 & i/3 & j/11\end{matrix}\end{equation*}

For that I have applied the Huffman code and I got the following tree:

Now it is asked for the total weight of the code. How do we calculate that?
Hey mathmari!

The total weight would be the weighted path length from the root.
The objective of the algorithm is to minimize the total weight, implying that compression is optimal. 🧐

Put differently, it is the length of the resulting code for each symbol multiplied by its frequency and then summed together.
So the contribution of $a$ is $4\times 2=8$, since $a$ is encoded by $0000$, which has length $4$ and it occurs $2$ times. 🤔

I think your tree is not optimal though. I found a different tree with a slightly lower total weight. (Sweating)
 
Greetings, I am studying probability theory [non-measure theory] from a textbook. I stumbled to the topic stating that Cauchy Distribution has no moments. It was not proved, and I tried working it via direct calculation of the improper integral of E[X^n] for the case n=1. Anyhow, I wanted to generalize this without success. I stumbled upon this thread here: https://www.physicsforums.com/threads/how-to-prove-the-cauchy-distribution-has-no-moments.992416/ I really enjoyed the proof...

Similar threads

  • · Replies 18 ·
Replies
18
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
26
Views
3K
  • · Replies 8 ·
Replies
8
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 17 ·
Replies
17
Views
1K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K