The Huffman coding tree function buildHuff of Figure 5.29 manipulates a sorted list. This could result in
Question:
The Huffman coding tree function buildHuff of Figure 5.29 manipulates a sorted list. This could result in a (Θn2) algorithm, because placing an intermediate Huffman tree on the list could take Θ(n) time. Revise this algorithm to use a priority queue based on a min-heap instead of a list.
In Figure 5.29
Transcribed Image Text:
// Build a Huffman tree from list hufflist static HuffTree buildTree (List hufflist) { HuffTree tmp1, tmp2, tmp3; LettFreq tmpnode; } for (hufflist.moveToPos (1); hufflist.length() > 1; hufflist.moveToPos (1)) { } // While at least two items left hufflist.moveToStart (); tmpl= hufflist.remove(); tmp2 = hufflist.remove(); tmpnode = new LettFreq (tmpl.weight () + tmp2.weight ()); tmp3 = new HuffTree (tmpnode, tmp1, tmp2); // return to the list in sorted order for (hufflist.moveToStart (); hufflist.currPos () < hufflist.length(); hufflist.next()) if (tmp3.weight () = hufflist.length()) hufflist.append (tmp3); // This is heaviest value hufflist.moveToStart (); // This is only tree on list return hufflist.remove(); // Return the tree.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 75% (4 reviews)
The provided algorithm in the image is for constructing a Huffman tree using a sorted list As mentioned in the question this could result in an ineffi...View the full answer
Answered By
Zubair Abdulla
.I am a 23 year experienced Professor of Chemistry with PhD in Chemical Technology with specialisation in Technology of Pharmaceuticals and Fine chemicals from Institute of Chemical Technology, Mumbai. I worked in drugs manufacturing industry for several years. Later, out of my passion for teaching and research, I shifted to academics teaching MSc and BSc organic chemistry in a college. For the last five years, I am teaching students online quite successfully
My interactive method of teaching chemistry is well appreciated by students both in India and abroad.
My industrial experience in drug manufacturing could make the students understand the topics from a practical point of view.
Dr. Zubair M A
0.00
0 Reviews
10+ Question Solved
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Question Posted:
Students also viewed these Computer science questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Huffman coding animation) Write a program that enables the user to enter text and displays the Huffman coding tree based on the text, as shown in Figure 25.23a. Display the weight of the subtree...
-
Write a program that enables the user to enter text and displays the Huffman coding tree based on the text, as shown in Figure 25.25a. Display the weight of the subtree inside the subtree?s root...
-
Read the case study about Joy Jowie Inc and write a detailed paper about it
-
A certain industrial process requires a steady stream of saturated vapor water at 200 kPa at a rate of 2 kg/s. There are two alternatives for supplying this steam from ambient liquid water at...
-
Why is normalization of a probability distribution important? What would one have to consider when working with a probability distribution that was not normalized?
-
What is the difference between internal ecological accounting and the other two types of ecological accountingexternal ecological accounting and other ecological accounting?
-
The manager of the customer service department of Omega Credit Card Service Company is concerned about the number of defects produced by the billing process, every day a random sample of 250...
-
The application of the supply-and-demand model. The objective of this activity is to enhance your understanding about the supply-and-demand model. Option 1: Every summer, when peaches are in season,...
-
Complete the implementation of the Huffman coding tree, building on the code presented in Section 5.6. Include a function to compute and store in a table the codes for each letter, and functions to...
-
Implement a priority queue class based on the max-heap class implementation of Figure 5.19. The following methods should be supported for manipulating the priority queue: void enqueue(int ObjectID,...
-
Write each equation in exponential form. In Ve 1 2
-
The adiabatic constant ( y ) of 1 . 0 0 L of an ideal gas is 1 . 3 0 . The gas's intial state to half is T = 2 7 3 K and P = 1 atm. Find the final ( a ) temperature and ( b ) pressure if it is...
-
What is the complexity of code chunk given below? (Consider list as an input.) public static void who knows (int[][] list) { int xDim = list.length; int yDim = list[0].length; for (int i = xDim; i >=...
-
On January 1, 2023, Fields Inc. enters into a 5-year non-cancellable lease with Wilson Ltd. for equipment that has an estimated useful life of 5 years and a fair value of $2,000,000. Fields has an...
-
A potted plant hangs by two cords. Each cord is 2 7 \ deg from the vertical as shown. Calculate the force in each individual cord if gravity is pulling straight down on the pot with a mass of 5 kg .
-
William Corp. enters into a contract with a customer to build an apartment building for $1,056,300. The customer hopes to rent apartments at the beginning of the school year and provides a...
-
The following are line items included in the 2012 statement of cash flows prepared by Goodlys Clothing Company. Depreciation expense..............$ 5,500 Increase in accounts receivable .............
-
What kind of financial pressures can an LBO cause?
-
Suppose we modify the deterministic version of the quick-sort algorithm so that, instead of selecting the last element in an n-element sequence as the pivot, we choose the element at index n/2. What...
-
Suppose we are given two n-element sorted sequences A and B each with distinct elements, but potentially some elements that are in both sequences. Describe an O(n)-time method for computing a...
-
Is our linked-list-based implementation of merge-sort (Code Fragment 12.3) stable? Explain why or why not. /** Merge contents of sorted queues S1 and S2 into empty queue S. */ public static void...
-
Name the type of shift used to describe the difference in the absorption and emission wavelengths and explain what happens to the energy?
-
1. A force of 6.27 N acts through a distance of 12 I'm in the direction of the force. Find the work done? 2. A car travels north at 26, I m's for 13.1 min. It then travels south at 41.3 m/s for 20.9...
-
Records available for the latest period are as follows: Support Depts. Customer Service Administration 580,000 $ 7 100 Total Costs $ # of Employees # of Customer Inquiries Operating Depts. Shirts...
Study smarter with the SolutionInn App