Taking reference of Huffman code algorithm,
list={{{{{{}, {{x7, 4}, {1, {{f, 3}}}, {0, {{q, 1}}}}},
{{x8,9}, {1, {{b, 5}}}, {0, {{x7, 4}}}}},
{{x9,12}, {1, {{e, 6}}}, {0, {{a, 6}}}}},
{{x10,19}, {1, {{h, 10}}}, {0, {{x8, 9}}}}},
{{x11,31}, {1, {{x10, 19}}}, {0, {{x9, 12}}}}}
This is in midway of creating the Huffman code for any string.
x* represents the new node made from two smallest nodes and 4 next to it represents the sum of the frequencies of the two child nodes under it.
Information on structure of list:
{{parent_node,fre1},{code,{{child_node1,freq2}}},{code,{{child_node2,freq3}}}}
freq1 = freq2 + freq3
{{x7, 4}, {1, {{f, 3}}}, {0, {{q, 1}}}}
x7 is parent of f and q
4 = 3 + 1
This unique node(x7) is added in list, sorted and operation repeated again. I am facing problem with creating a final output as Huffman codes for each character, for example, h = 11, a = 00 walking from top to bottom. Final result could be {{h,11},{a,00}} and with other characters.
Comments
Post a Comment