Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2018:journals:nasona:chapter4 [2018/03/11 15:26] – [4.8 Huffman Codes] nasona | courses:cs211:winter2018:journals:nasona:chapter4 [2018/03/11 22:01] (current) – [4.8 Huffman Codes] nasona | ||
|---|---|---|---|
| Line 301: | Line 301: | ||
| ======= 4.8 Huffman Codes ======= | ======= 4.8 Huffman Codes ======= | ||
| - | • A greedy rule is used to shrink | + | |
| - | • The global consequences | + | ==Summary== |
| - | • Data compression, | + | We want to map encodings to letters so that no encoding is the prefix of another in order to avoid ambiguity. |
| ==The Problem== | ==The Problem== | ||
| + | * A greedy rule is used to shrink the size of the problem instance so that an equivalent smaller problem can then be solved by recursion | ||
| + | * The global consequences of the initial greedy decision do not become fully apparent until the full recursion is complete | ||
| + | * Data compression, | ||
| * The mapping of bit strings to symbols is arbitrary | * The mapping of bit strings to symbols is arbitrary | ||
| * The letters in most human alphabets do not get used equally frequently | * The letters in most human alphabets do not get used equally frequently | ||
| Line 352: | Line 355: | ||
| ==Huffman’s Algorithm== | ==Huffman’s Algorithm== | ||
| To construct a prefix code for an alphabet S, with given frequencies: | To construct a prefix code for an alphabet S, with given frequencies: | ||
| - | | + | If S has two letters: |
| - | Encode one letter using 0 and the other using 1 | + | Encode one letter using 0 and the other using 1 |
| - | Else: | + | |
| - | Let y* and z* be the two lowest-frequency letters | + | Let y* and z* be the two lowest-frequency letters |
| - | Form a new alphabet S’ by deleting y* and z* and replacing them with a new letter w of frequency fy*+fz* | + | Form a new alphabet S’ by deleting y* and z* and replacing them with a new letter w of frequency fy*+fz* |
| - | Recursively construct a prefix code y’ for S’, with tree T’ | + | Recursively construct a prefix code y’ for S’, with tree T’ |
| - | Define a prefix code for S as follows: | + | 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* | + | |
| - | Endif | + | Endif |
| * The greedy rule underlying Huffman’s Algorithm – the merging of the two lowest frequency letters – fits into the structure of the algorithm as a whole | * The greedy rule underlying Huffman’s Algorithm – the merging of the two lowest frequency letters – fits into the structure of the algorithm as a whole | ||
| Line 374: | Line 377: | ||
| * Each iteration, which performs three of these operations, takes time O(logk) | * Each iteration, which performs three of these operations, takes time O(logk) | ||
| * Summing over all k iterations, we get a total runtime of O(klogk) | * Summing over all k iterations, we get a total runtime of O(klogk) | ||
| - | Extensions | + | ==Extensions== |
| * The challenge here is to define an encoding schedule where the notion of using fractions of bits is well-defined | * The challenge here is to define an encoding schedule where the notion of using fractions of bits is well-defined | ||
| * Another drawback of prefix codes is that they cannot adapt to changes in the text | * Another drawback of prefix codes is that they cannot adapt to changes in the text | ||
| + | ==Additional Information== | ||
| + | A concept that was troubling me in the beginning stages of understanding Huffman codes was the concept of the meta-letter that is the parent of leaf nodes. As a read the section after the class, it made more sense. The meta-letter is there because a letter node cannot be there. A letter encoding cannot be an interior node because that means that it is the prefix of another node, which is the point of the Huffman codes. There can be no encoding that is the prefix of another. Moreover, meta-letters are helpful and make more sense in Huffman' | ||
| + | |||
| + | On a scale of 1 to 10, the readability of this section is a 9. The book explained really well the notation and the concepts behind the Huffman Code. Also, the main part of the code involved binary trees, which we've already seen multiple times in this class, so it was really building off the knowledge we already knew. | ||
