문제

I am trying to find the length of code generated on Huffman encoding for finding Huffman compression efficiency:

My code for Huffman encoding is:

Function call is GenerateCode(rear, "",Obj); These Obj is used for internal purpose(you may feel it un-necessary but i am using it to have the data in current context).

    public void GenerateCode(Node parentNode, string code, MainPage obj)
    {
        obj.listBox2.Visibility = Visibility.Visible;
        if (parentNode != null)
        {
            GenerateCode(parentNode.left, code + "0",obj);
            if (parentNode.left == null && parentNode.right == null)
               obj.listBox2.Items.Add("Symbol :" + parentNode.symbol + " - " + "Code : " + code);
               GenerateCode(parentNode.right, code + "1",obj);
        }
    } 

And suppose Huffman Table obtained is this :

symbol : 0 Code : 1
symbol : 1 Code : 00
symbol : 2 Code : 011
symbol : 3 Code : 010

Now i am not able to find the logic in c# to calculate the length on these encoding corresponding to each symbols so that i would be able to multiply them with frequency to calculate the Huffman compression efficiency. Because they are string of "0 and 1" so how to calculate the length from them ?

도움이 되었습니까?

해결책

Length will be code.Length, length in bytes will be (float)code.Length / 8. Important is to compare with original length in the same units, bits or bytes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top