Decompressing Text There are two functions that work together to decompress text: a generate_tree_xxx function to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Decompressing Text There are two functions that work together to decompress text: a generate_tree_xxx function to generate a tree from its representation in a file, and a decompress_bytes function to generate the text itself. First, the functions to generate a Huffman tree from its file representation. Note that you are being asked to write two different generate_tree_xxx functions. Once you get one of them working, you can successfully decompress text. But we're asking for both, so don't forget to do the other one! generate_tree_general takes a list of ReadNodes representing a tree in the form that it is stored in a file. It reconstructs the Huffman tree and returns the root HuffmanTree object. This function assumes nothing about the order in which the nodes are given in the list. As long as it is given the index of the root node, it will be able to reconstruct the tree. This means that the tree nodes could have been written in postorder (as your assignment does), preorder, inorder, level-order, random-order, whatever. Note that the number of each node in the list corresponds to the index of the node in the list. That is, the node at index 0 in the list has node-number 0, the node at index 1 in the list has node-number 1, etc. # # Functions for decompression def generate_tree_general(node_lst: list[ReadNode], root_index: int) -> HuffmanTree: """ Return the Huffman tree corresponding to node_lst[root_index]. The function assumes nothing about the order of the tree nodes in the list. >>> 1st = [ReadNode(0, 5, 0, 7), ReadNode (0, 10, 0, 12), \ ReadNode (1, 1, 1, 0)] >>> generate_tree_general (1st, 2) Huffman Tree (None, Huffman Tree (None, Huffman Tree (10, None, None), \ Huffman Tree (12, None, None)), \ Huffman Tree (None, Huffman Tree (5, None, None), Huffman Tree (7, None, None))) || || || # TODO: Implement this function ht= Huffman Tree () Decompressing Text There are two functions that work together to decompress text: a generate_tree_xxx function to generate a tree from its representation in a file, and a decompress_bytes function to generate the text itself. First, the functions to generate a Huffman tree from its file representation. Note that you are being asked to write two different generate_tree_xxx functions. Once you get one of them working, you can successfully decompress text. But we're asking for both, so don't forget to do the other one! generate_tree_general takes a list of ReadNodes representing a tree in the form that it is stored in a file. It reconstructs the Huffman tree and returns the root HuffmanTree object. This function assumes nothing about the order in which the nodes are given in the list. As long as it is given the index of the root node, it will be able to reconstruct the tree. This means that the tree nodes could have been written in postorder (as your assignment does), preorder, inorder, level-order, random-order, whatever. Note that the number of each node in the list corresponds to the index of the node in the list. That is, the node at index 0 in the list has node-number 0, the node at index 1 in the list has node-number 1, etc. # # Functions for decompression def generate_tree_general(node_lst: list[ReadNode], root_index: int) -> HuffmanTree: """ Return the Huffman tree corresponding to node_lst[root_index]. The function assumes nothing about the order of the tree nodes in the list. >>> 1st = [ReadNode(0, 5, 0, 7), ReadNode (0, 10, 0, 12), \ ReadNode (1, 1, 1, 0)] >>> generate_tree_general (1st, 2) Huffman Tree (None, Huffman Tree (None, Huffman Tree (10, None, None), \ Huffman Tree (12, None, None)), \ Huffman Tree (None, Huffman Tree (5, None, None), Huffman Tree (7, None, None))) || || || # TODO: Implement this function ht= Huffman Tree ()
Expert Answer:
Related Book For
Introduction to Operations and Supply Chain Management
ISBN: 978-0132747325
3rd edition
Authors: Cecil B. Bozarth, Robert B. Handfield
Posted Date:
Students also viewed these programming questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
Which group, if any, should the Diamond Peak Hotel accept? Why? What other questions might the general manager ask to make an effective decision? How would you deny one of the groups? What would you...
-
Explain the investigation process As an HR manager, identify the first three steps you recommend the HR team take to begin to investigate this scenario. Explain how the steps you are recommending are...
-
Tsang Corporation operates in a state with no sales tax. The company uses the perpetual inventory system. Record the following transactions in a general journal: DATE TRANSACTIONS 2019 June 5 Sold...
-
A man of mass 70 kg climbs stairs of vertical height 2.5 m. Calculate the work done against the force of gravity. (Take g = 9.81 m s 2 .)
-
Report writing is very time-consuming. What should be added to a trending database to quickly interrogate vibration data yet yield a quality report?
-
Caruba Company issued $400,000, 9%, 20-year bonds on January 1, 2012, at 103. Interest is payable semiannually on July 1 and January 1. Caruba uses straight-line amortization for bond premium or...
-
what are some the limitations of title VII of the Civil Rights Act- E? what are some of the limitations of equal Pay Act of 1963? what are some of the limitations of age Discrimination in Employment...
-
The director of laboratory services at Henry Hospital is assessing her staffing requirements. The hospital processes 1,440,000 lab tests per year. A lab tech can process 50 per day and earns $50,000...
-
Bromine has a melting point of -7.2 degree Celsius and a boiling point of 58.8 degree Celsius. (a) What is the physical state of bromine at -20.0 degree Celsius? (b) What is the physical state of...
-
A special "catch all" Keno ticket allows you to play a six-spot ticket that pays only if you pick all 6 numbers. It costs \(\$ 5\) to play and pays \(\$ 27,777\) if you win. What is your expectation...
-
We know that in a game of U.S. roulette, the probability that the ball drops into any one slot is 1 out of 38 . Suppose that there are two balls spinning at once, and that it is physically possible...
-
Consider a state lottery that has a weekly television show. On this show, a contestant receives the opportunity to win \(\$ 1\) million. The contestant picks from four hidden windows. Behind each is...
-
This experiment has two mutually exclusive events, \(A\) and \(\bar{A}\), that form a partition of the sample space \(S\). The number of elements in each set is shown in each region. Find the...
-
The odds against winning a certain "Power Ball" lotto are 150 million to 1. Make up an example to help visualize these odds.
-
Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. The Fan class VideoNote...
-
1. Following are information about Alhadaf Co. Cost incurred Inventory Purchases Sales Adverting expense Salary Expense Depreciation Beginning Inventory Ending Inventory Amount 118,000 350.000 90,000...
-
Republic Tool and Manufacturing Company of Carlsbad, California, makes a wide variety of lawn care products. One of Republics products is the Model Number 540 Broadcast Spreader: Complete the...
-
Returning to Example 4.1 and Figure 4.6, suppose management actually does put a system in place that lets customers enter orders electronically, with this information sent directly to the picking...
-
What is MRP nervousness? Can this condition affect DRP systems as well?
-
Frieda Wannamaker is a taxable investor who is currently in the 28% income-tax bracket. She is considering purchasing a tax-exempt bond with a yield of 3.75%. The taxable equivalent yield on this...
-
Holding constant all other variables and excluding any interactions among the determinants of value, which of the following would most likely increase a firms price-to-earnings multiple? a. The risk...
-
Technical analysis looks at the demand and supply for securities based on trading volumes and price studies. Charting is a common method used to identify and project price trends in a security. A...
Study smarter with the SolutionInn App