Chapter 5: Q13E (page 162)
A long string consists of the four characters ; they appear with frequency and respectively. What is the Huffman encoding of these four characters?
Short Answer
Huffman encoding of the characters is respectively.
Chapter 5: Q13E (page 162)
A long string consists of the four characters ; they appear with frequency and respectively. What is the Huffman encoding of these four characters?
Huffman encoding of the characters is respectively.
All the tools & learning materials you need for study success - in one app.
Get started for freeSuppose we want to find the minimum spanning tree of the following graph.
(a) Run Prim’s algorithm; whenever there is a choice of nodes, always use alphabetic ordering (e.g., start from node A). Draw a table showing the intermediate values of the cost array.
(b) Run Kruskal’s algorithm on the same graph. Show how the disjoint-sets data structure looks at every intermediate stage (including the structure of the directed trees), assuming path compression is used.
The basic intuition behind Huffman’s algorithm, that frequent blocks should have short encodings and infrequent blocks should have long encodings, is also at work in English, where typical words like I, you, is, and, to, from, and so on are short, and rarely used words like velociraptor are longer.
However, words like fire!, help!, and run! are short not because they are frequent, but perhaps because time is precious in situations where they are used.
To make things theoretical, suppose we have a file composed of m different words, with frequencies . Suppose also that for the word, the cost per bit of encoding is . Thus, if we find a prefix-free code where the word has a codeword of length , then the total cost of the encoding will be localid="1659078764835" .
Show how to modify Huffman’s algorithm to find the prefix-free encoding of minimum total cost.
Give the state of the disjoint-sets data structure after the following sequence of operations, starting from singleton sets . Usepath compression. In the case of ties, always make the lower numbered root point to the higher numbered ones.
A binary counter of unspecified length supports two operations: increment (which increases its value by one) and reset (which sets its value back to zero). Show that, starting from an initially zero counter, any sequence of n increment and reset operations takes time ; that is, the amortized time per operation is O(1) .
Give You are given a graphwith positive edge weights, and a minimum spanning tree with respect to these weights; you may assume GandTare given as adjacency lists. Now suppose the weight of a particular edge is modified fromw(e)to a new value w'(e). You wish to quickly update the minimum spanning tree T to reflect this change, without recomputing the entire tree from scratch. There are four cases. In each case give a linear-time algorithm for updating the tree.
(a) and .
(b) role="math" localid="1658907878059" and .
(c) role="math" localid="1658907882667" and .
(d) role="math" localid="1658907887400" and .
What do you think about this solution?
We value your feedback to improve our textbook solutions.