# HW6 - Q7 ###### tags: `演算法`, `109-2` :::success https://hackmd.io/@Cing-Chen/r10ALDxLd ::: ## Question **Exercises 16.3-3** What is an optimal Huffman code for the following set of frequencies, based on the first 8 Fibonacci numbers? \begin{align} a:1\\ b:1\\ c:2\\ d:3\\ e:5\\ f:8\\ g:13\\ h:21 \end{align} Can you generalize your answer to find the optimal code when the frequencies are the first n Fibonacci numbers? ## Mein Answer <!-- 看到 Can you...? 開頭的問題一律先說 I can't 感謝你閱讀本次解答,我們下次見~ 沒有啦 我還想要分數 不想再修一次啦 --> ### Huffman Tree 既然 A~H 是肺部鈉氣數列,表示已經 sort 好了,那就直接建樹吧 ![](https://i.imgur.com/gQxjJbD.png) \begin{align} a:0000000\\ b:0000001\\ c:000001\\ d:00001\\ e:0001\\ f:001\\ g:01\\ h:1 \end{align} ### Excuse me WTF ![](https://i.imgur.com/d794ymI.png) Optical code `F[i] = f[k+2] - 1`