This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: o Make a tree in which the root is the sum of the probabilities o S: W U E $ Can only be done if no code is the prefix of another • Huffman coding guarantees this because chars are leaf nodes Char Code A 010 T 011 W 110 U 111 E 00 $ 10 Getting the probabilities • Total # of chars=n • Scan the text: O(n) • Put in array of size n • Sort list: o Time: O(n) o Space: O(k) o Highest frequency=k o Make array of LL size k o Frequency=index o Put every char in n into k Time to build tree • # of chars=c • Basic operations 1. Make a new node: O(1) • Total= O(c) 1. Enqueue (includes probability comparison): O(1) • Total= O(c) 1. Dequeue(includes probability comparison): O(1) • Total= O(c) • How many nodes in the tree? o 2c-1 Total Time: O(n)+O(c)=O(n) Total Space: O(c) + O(k)+ O(c)= O(c+k)...
View Full Document
This note was uploaded on 02/29/2012 for the course 198 112 taught by Professor Venugopal during the Spring '09 term at Rutgers.
- Spring '09