Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2012:journals:jeanpaul:chapterfour_sectionviii [2012/03/06 04:48] – [The Problem] mugabej | courses:cs211:winter2012:journals:jeanpaul:chapterfour_sectionviii [2012/03/06 05:27] (current) – [Implementation and Running Time] mugabej | ||
|---|---|---|---|
| Line 27: | Line 27: | ||
| * |γ(x)|: Length of encoding of x | * |γ(x)|: Length of encoding of x | ||
| * ABL = Σ< | * ABL = Σ< | ||
| - | * ABL is the Average | + | * ABL is the Average |
| \\ | \\ | ||
| \\ | \\ | ||
| Line 42: | Line 42: | ||
| * Each time the path goes from a node to its right child, we write down a 1 | * Each time the path goes from a node to its right child, we write down a 1 | ||
| * The Encoding of S constructed from T is a prefix code | * The Encoding of S constructed from T is a prefix code | ||
| + | * The search for an optimal prefix code reduces to the search of a binary Tree T, together with a labeling of the leaves of T, that minimizes the ABL. | ||
| + | * Thus the length of the encoding of a letter x in S is simply the length from the root to the leaf labeled x: This length is termed the ** depth** of the leaf, and the depth of a leaf v in T will be denoted by depth< | ||
| + | * So now our goal is to find the labeled tree T that minimizes the weighted average of the depths of all leaves, where the average is weighted by the frequencies of the letters that label the leaves: ∑< | ||
| + | * The Binary Tree corresponding to the optimal prefix code is full | ||
| + | ==== Algorithm to Construct an Optimal Prefix Code ==== | ||
| + | |||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | \\ | ||
| + | * The algorithm above is referred to as the //Huffman Algorithm// and the prefix code it produces is termed the //Huffman code// | ||
| + | * This algorithm produces an optimal prefix code | ||
| + | * This algorithm also follows a bottom-up approach as seen: It focuses on the leaves representing the two lowest-frequency letters, and then continues by recursion. | ||
| + | \\ | ||
| + | \\ | ||
| + | ==== Analyzing the Algorithm ==== | ||
| + | |||
| + | * The algorithm is optimal | ||
| + | * ABL(T' | ||
| + | * The Huffman code for a given alphabet achieves the minimum ABL of any prefix code | ||
| + | |||
| + | ==== Implementation and Running Time ==== | ||
| + | |||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | \\ | ||
| + | So overall takes O(nlogn).\\ | ||
| + | \\ | ||
| + | Very intriguing section although its proofs were long. I give it an 8/10. | ||
| + | |||
| + | |||
| + | |||
