CS 240
Lab 13

Purpose:  Learning about various uses and representations of trees.
Reading:  Chapters 15, pp. 832-863

Exercises:

1.        In 1952, Huffmann (while a graduate student) devised an algorithm that could be used to construct a variable-length set of codes to represent the characters (or words) that make up a given text.  This algorithm is an example of a greedy algorithm (i.e., an algorithm that determines a globally optimal solution by making locally optimal choices).  The encoding schemes generated are immediately decodable, and each character is guaranteed to have a minimal expected code length.

Given the following characters and their weights:

                ~ = .02         @ = .18          # = .10          $ = .12          % = .10          & = .28          * = .20

Generate a Huffman tree for the above characters with respect to the given weights.

Use the tree to derive the code assigned to each character.  Compute the expected code length.

Is the tree generated the only one that can be generated for this problem set?  ________________________

Are the codes generated the only ones that can be generated for this problem set?  ____________________


1.        AVL trees are binary search trees in which the balance factor or each node is 0, 1, or -1.  When insertions to an AVL tree cause it to become unbalanced, the tree is rebalanced through one or more rotation operations.

Show the construction of the AVL tree that results from inserting the following numbers in the order given.  Show the tree and balance factors for each node before and after each rebalancing:  100, 200, 700, 12, 500, 17, 350, 16, 54, 400, 600, 800.

 

2.        Unlike AVL trees, which must be rebalanced after almost half of the insertions (and are binary trees), 2-3-4 trees remain balanced during insertion.  A 2-3-4 tree is one in which each node stores at most three data values, each non-leaf node is a 2-node, a 3-node, or a 4-node, and all the leaves are on the same level.

Given a 2-3-4 tree, the root of which contains the elements 100, 200, and 700, insert the following
elements using Top-Down insertion in the order given:  12, 500, 17, 350, 16, 54, 400, 600, 800
(Show the insertion in stages by drawing a new tree each time a node is split).