Optimal Huffman Code for Fibonacci numbers

北慕城南 提交于 2019-12-06 14:36:06

Read - http://en.wikipedia.org/wiki/Huffman_coding - In particular, pay attention to the phrase "A binary tree is generated from left to right taking the two least probable symbols and putting them together to form another equivalent symbol having a probability that equals the sum of the two symbols. The process is repeated until there is just one symbol".

How does the above relate to the fibonacci series?

Huffman coding algorithm takes two least frequency nodes and connects them to form a parent which has frequency equal sum of child nodes. In random frequency of symbols we need to compute the least two nodes to combine every time but in case of fibonacci sequence of frequecy the sequence in fibonacci series is same as sequence in huffman coding.

example: - a : 1, b : 1, c : 2, d : 3, e : 5, f : 8, g : 13, h : 21

it will form a left skewed or right skewed tree where the coding of each symbol can be derived using simple formula

if n is no of symbols

a = (n-2)*0 + 0

b = (n-2)*0 + 1

c = (n-3)*0 + 1

d = (n-4)*0 + 1

e = (n-5)*0 + 1

. . . last = 1

so for above example

a = (n-2)*0 + 0 = (6)*0 + 0 = 0000000

b = (6)*0 + 1 = 0000001

c = (5)*0 + 1 = 000001

.......

I hope u r getting the pattern

interesting thing is calculation of average bit length

avg = ((n-1)*2 + sumof((n-i+1)*fib(i)) where i in (3,n))/(sumof(fib(i)) where i in (1,n))

the above can simplified to direct formula.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!