-
Notifications
You must be signed in to change notification settings - Fork 4
Huffman Trees
Anthony Christe edited this page Nov 15, 2013
·
6 revisions
- Each node has 0 or 2 children
- Only leaf nodes contain data
- Data in each leaf node is unique
- Basic compression
- Performs compression on characters (not entire words)
- Represent most frequent characters using shortest bit-length
- Create a table of values mapping characters to their frequencies
- Create a priority queue where the key is the frequency and the data is the character (minimum values have higher priority)
- Insert all of the values from the table into the priority queue
- If the priority queue has a single element, you're done, this is the root of the tree
- Poll the priority queue twice and create a binary tree with those nodes
- Add the frequencies of the newly created tree and offer back to the priority queue
- Return to step 4
- Create a Huffman tree for the data humuhumunukunukuapuaa
| Character | Frequency |
|---|---|
| u | 9 |
| p | 1 |
| a | 3 |
| n | 2 |
| m | 2 |
| k | 2 |
| h | 2 |