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
AI Thread 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)
 
I was reading documentation about the soundness and completeness of logic formal systems. Consider the following $$\vdash_S \phi$$ where ##S## is the proof-system making part the formal system and ##\phi## is a wff (well formed formula) of the formal language. Note the blank on left of the turnstile symbol ##\vdash_S##, as far as I can tell it actually represents the empty set. So what does it mean ? I guess it actually means ##\phi## is a theorem of the formal system, i.e. there is a...

Similar threads

Replies
18
Views
1K
Replies
1
Views
1K
Replies
4
Views
4K
Replies
8
Views
954
Replies
6
Views
2K
Replies
1
Views
1K
Replies
17
Views
1K
Replies
9
Views
2K
Back
Top