Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

a. Describe the Huffman coding algorithm for constructing an optimal code for a set of symbols, given the frequency of these symbols.

b. Use Huffman coding to find an optimal code for these symbols and frequencies: \({\bf{A}}:{\bf{0}}.{\bf{2}},{\bf{B}}:{\bf{0}}.{\bf{1}},{\bf{C}}:0.3,{\bf{D}}:{\bf{0}}.{\bf{4}}\).

Short Answer

Expert verified

Huffman coding:

For every given symbol \(v\), we draw a tree consisting of a vertex \(v\) alone (these trees then form a forest).

The weight of the tree containing \(v\) is then the frequency of the symbol.

At every step of the Huffman coding algorithm, select the two trees \({T_1}\) and \({T_2}\) with the lowest frequencies (in case of a tie, arbitrarily chose one of the trees with the lowest or second lowest frequency).

We replace these two trees \({T_1}\) and \({T_2}\) by one new tree, which has a root with \({T_1}\) as its left child and \({T_2}\) as its right child (assuming that \({T_1}\) has a higher frequency than \({T_2}\)). The weight of the tree is the sum of the weight of \({T_1}\) and the weight of \({T_2}\). Repeat this procedure until the forest contains exactly one tree.

\(\begin{array}{c}A:000\\B:001\\C:01\\D:1\end{array}\)

Step by step solution

Achieve better grades quicker with Premium

  • Unlimited AI interaction
  • Study offline
  • Say goodbye to ads
  • Export flashcards

Over 22 million students worldwide already upgrade their learning with Vaia!

01

Definition

Huffman coding:

For every given symbol v, we draw a tree consisting of a vertex v alone (these trees then form a forest).

The weight of the tree containing \(v\) is then the frequency of the symbol.

At every step of the Huffman coding algorithm, select the two trees \({T_1}\) and \({T_2}\) with the lowest frequencies (in case of a tie, arbitrarily chose one of the trees with the lowest or second lowest frequency).

One replaces these two trees \({T_1}\) and \({T_2}\) by one new tree, which has a root with \({T_1}\) as its left child and \({T_2}\) as its right child (assuming that \({T_1}\) has a higher frequency than \({T_2}\)). The weight of the tree is the sum of the weight of \({T_1}\)and the weight of \({T_2}\). Repeat this procedure until the forest contains exactly one tree.

02

Huffman coding

Huffman coding

\(\begin{array}{c}A:{\bf{0}}{\bf{.2}}\\{\bf{B:0}}{\bf{.1}}\\{\bf{C:0}}{\bf{.3}}\\{\bf{D:0}}{\bf{.4}}\end{array}\)

One has been given \({\bf{4}}\) symbols. One will then draw a forest of \({\bf{4}}\) trees containing \({\bf{1}}\) vertex each, while the vertex has the above names and are labelled with the given values.

03

Weight of the edge

One notes that \(A\) and \(B\) have the smallest weights.

One will then replace their trees with a new tree that has a root with a left and right child. The edge to the left child is labeled \({\bf{0}}\) and the edge to the right child is labeled \({\bf{1}}\). The left child is named \(A\) (highest weight of the two) and the right child is named \(B\) (Iowest weight of the two).

The weight of the new tree is the sum of the weight of the trees that were replaced.

04

Step 4:Smallest weight of the edge

One notes that \(A + B\) and \({\bf{C}}\) have the smallest weights (note: \(A + B\) represents the tree with leaves \(A\) and \(B\)).

One will then replace their trees with a new tree that has a root with a left and right child. The edge to the left child is labeled \({\bf{0}}\) and the edge to the right child is labeled \({\bf{1}}\). The left child is named \(A + B\) (highest weight of the two) and the right child is named \({\bf{C}}\) (lowest weight of the two).

The weight of the new tree is the sum of the weight of the trees that were replaced.

05

Lowest weight of the tree

One notes that \(A + B\) and \({\bf{D}}\) have the smallest weights (note: \(A + B\) represents the tree with leaves \(A\) and \(B\)).

One will then replace their trees with a new tree that has a root with a left and right child. The edge to the left child is labeled \({\bf{0}}\) and the edge to the right child is labeled \({\bf{1}}\). The left child is named \(A + B\) (highest weight of the two) and the right child is named \({\bf{D}}\) (lowest weight of the two).

The weight of the new tree is the sum of the weight of the trees that were replaced.

06

Encoding

The encoding of the letters is then the sequence of labels of the edges in the path from the root to the letter.

\(\begin{array}{c}A:000\\B:001\\C:01\\D:1\end{array}\)

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Explain how breadth-first search and how depth-first search can be used to determine whether a graph is bipartite.

What is the level of each vertex of the rooted tree in Exercise \(4\)?

Sollin's algorithm produces a minimum spanning tree from a connected weighted simple graph \({\bf{G = (V,E)}}\) by successively adding groups of edges. Suppose that the vertices in \({\bf{V}}\) are ordered. This produces an ordering of the edges where \({\bf{\{ }}{{\bf{u}}_{\bf{0}}}{\bf{,}}{{\bf{v}}_{\bf{0}}}{\bf{\} }}\) precedes \({\bf{\{ }}{{\bf{u}}_{\bf{1}}}{\bf{,}}{{\bf{v}}_{\bf{1}}}{\bf{\} }}\) if \({{\bf{u}}_{\bf{0}}}\) precedes \({{\bf{u}}_{\bf{1}}}\) or if \({{\bf{u}}_{\bf{0}}}{\bf{ = }}{{\bf{u}}_{\bf{1}}}\) and \({{\bf{v}}_{\bf{0}}}\) precedes \({{\bf{v}}_{\bf{1}}}\). The algorithm begins by simultaneously choosing the edge of least weight incident to each vertex. The first edge in the ordering is taken in the case of ties. This produces a graph with no simple circuits, that is, a forest of trees (Exercise \({\bf{24}}\) asks for a proof of this fact). Next, simultaneously choose for each tree in the forest the shortest edge between a vertex in this tree and a vertex in a different tree. Again the first edge in the ordering is chosen in the case of ties. (This produces a graph with no simple circuits containing fewer trees than were present before this step; see Exercise \({\bf{24}}\).) Continue the process of simultaneously adding edges connecting trees until \({\bf{n - 1}}\) edges have been chosen. At this stage a minimum spanning tree has been constructed.

Show that the addition of edges at each stage of Sollinโ€™s algorithm produces a forest.

a. Explain how to use preorder, in-order, and post-order traversals to find the pre-fix, in-fix, and post-fix forms of an arithmetic expression.

b. Draw the ordered rooted tree that represents \({\bf{((x - 3) + ((x/4) + (x - y)}} \uparrow {\bf{3))}}\)

c. Find the pre-fix and post-fix forms of the expression in part \(\left( {\bf{b}} \right)\).

In Exercises 2โ€“6 find a spanning tree for the graph shown byremoving edges in simple circuits.

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free