Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2018:journals:bairdc:chapter4 [2018/03/12 23:37] – bairdc | courses:cs211:winter2018:journals:bairdc:chapter4 [2018/03/13 03:55] (current) – [4.8 – Huffman Codes and Data Compression] bairdc | ||
|---|---|---|---|
| Line 93: | Line 93: | ||
| ===== 4.8 – Huffman Codes and Data Compression ===== | ===== 4.8 – Huffman Codes and Data Compression ===== | ||
| + | |||
| + | The goal of Huffman Codes is lossless data compression. The original top-down approach created by Shannon and Fano isn't guaranteed to always produce an optimal code. So, Huffman came up with a bottom-up approach that did. The idea in this is to have the most frequently used characters to have the shortest codes in order to optimize the overall compression. Furthermore, | ||
| + | |||
| + | Using a Priority Queue, we can get Huffman' | ||
| + | < | ||
| + | if S has two letters: | ||
| + | Encode one letter as 0 and the other letter as 1 | ||
| + | else: | ||
| + | Let y* and z* be the two lowest-frequency letters | ||
| + | Form a new alphabet S’ by deleted y* and z* and replacing | ||
| + | them with a new letter w of freq fy* + fz* Recursively construct a prefix code y’ for S’ with tree T’ | ||
| + | Define a prefix code for S as follows: | ||
| + | Start with T’ | ||
| + | Take the leaf labeled w and add two children below it | ||
| + | labeled y* and z* | ||
| + | </ | ||
| + | |||
| + | I'd give this section a 10/10 on readability and interestingness. I was very interested in the topic, and it was explained well. | ||
