Close
Close Window

OpenDSA Stand-alone Modules

Chapter 0 modules

Show Source |    | About   «  0.97. Huffman Coding Trees   ::   Contents   ::   0.99. Proof of Optimality for Huffman Coding  »

Trees versus Tries

1. Trees versus Tries

We see that all letters with codes beginning with ‘0’ are stored in the left branch, while all letters with codes beginning with ‘1’ are stored in the right branch. Contrast this with storing records in a BST. There, all records with key value less than the root value are stored in the left branch, while all records with key values greater than the root are stored in the right branch.

Recall that the Huffman coding tree stored in the left branch all letters whose codes start with 0, and in the right branch all letters whose codes start with 1. We can use this same concept to store records in a search tree that is slightly different from the behavior of a BST. We can view all keys stored as appearing on a numberline. The BST splits the numberline based on the positions of key values as it receives them. In contrast, we could split key values based on their binary reprsentation similar to what the Huffman coding tree does. The following slideshows present this in more detail.

0 / 0 Settings
<<<>>>

We now add 18 to the tree. A split is made at 18.

Created with Raphaël 2.1.2
Created with Raphaël 2.1.2
36
18
0
70
36
18
Proficient Saving... Error Saving
Server Error
Resubmit


0 / 0 Settings
<<<>>>

We now want to add 45. This requires two splits. The first split is at value 48.

Created with Raphaël 2.1.2
Created with Raphaël 2.1.2
32
16
48
7
19
38
0
64
38
32
19
16
7
48
Proficient Saving... Error Saving
Server Error
Resubmit

   «  0.97. Huffman Coding Trees   ::   Contents   ::   0.99. Proof of Optimality for Huffman Coding  »

nsf
Close Window