Huffman codes compress text by assigning the characters that occur at the highest frequency the shortest...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Huffman codes compress text by assigning the characters that occur at the highest frequency the shortest possible codes. In this encoding scheme, no code can be a prefix of another. For example, if the code for a is 01, then the code for b cannot be 011. Given an array of Huffman code mappings and a Huffman-encoded string, find the decoded string. Each mapping will be a string consisting of a tab-separated character and its encoded value: 'c encoded value' where the whitespace is a tab character. The newline character is represented as the character (newline] in the codes list, but should translate to n when decoded. For example, given codes = ('a 100100, 'b 100101' Inewline] 111111') and the string encoded = 100100111111100101 we do the following. Break encoded into its constituent encodings. 100100 111111 100101 Now map them to their characters and return the string: 'anb'. This will print as: b Function Description Complete the function decode in the editor below. The function must return the decoded string. decode has the following parameter(s): codes(codes(0).codes[n-1]]: an array of character mappings encoded: an encoded string Constraints • 1sns 100 • 1 s Jencoded s 7000 • All characters of encoded are either '0' or '1' • All inputs will represent a valid Huffman encoded string v Sample Case 0 Sample Input a 100100 100101 110001 d 100000 [newline] 111111 111110 000001 111110000001100100111111100101110001111110 Sample Output pga bcp Explanation encoded: Character Code 11111080000110010011111110010111000111111O a 100100 b 100101 110001 111110 000001 180100 111111 180101 110001 111110 100000 a \n [newline] 111111 111110 decoded: 000001 pqa\nbcp This diagram depicts the conversion from 111110000001100100111111100101110001111110 to pqavnbcp. v Sample Case 1 Sample Input a 100100 b. 100101 110001 d. (newline] 100000 111111 100100111111100101110001100000 Sample Output a bcd Explanation encoded: 100100111111100101110001100000 Character Code a 100100 b 100101 100100 111111 100101 110001 108000 110001 a \n 100000 Inewline] 111111 decoded: a\nbcd This diagram depicts the conversion from 100100111111100101110001100000 to a\nbcd. string decode (vector<string> codes, string encoded) { Huffman codes compress text by assigning the characters that occur at the highest frequency the shortest possible codes. In this encoding scheme, no code can be a prefix of another. For example, if the code for a is 01, then the code for b cannot be 011. Given an array of Huffman code mappings and a Huffman-encoded string, find the decoded string. Each mapping will be a string consisting of a tab-separated character and its encoded value: 'c encoded value' where the whitespace is a tab character. The newline character is represented as the character (newline] in the codes list, but should translate to n when decoded. For example, given codes = ('a 100100, 'b 100101' Inewline] 111111') and the string encoded = 100100111111100101 we do the following. Break encoded into its constituent encodings. 100100 111111 100101 Now map them to their characters and return the string: 'anb'. This will print as: b Function Description Complete the function decode in the editor below. The function must return the decoded string. decode has the following parameter(s): codes(codes(0).codes[n-1]]: an array of character mappings encoded: an encoded string Constraints • 1sns 100 • 1 s Jencoded s 7000 • All characters of encoded are either '0' or '1' • All inputs will represent a valid Huffman encoded string v Sample Case 0 Sample Input a 100100 100101 110001 d 100000 [newline] 111111 111110 000001 111110000001100100111111100101110001111110 Sample Output pga bcp Explanation encoded: Character Code 11111080000110010011111110010111000111111O a 100100 b 100101 110001 111110 000001 180100 111111 180101 110001 111110 100000 a \n [newline] 111111 111110 decoded: 000001 pqa\nbcp This diagram depicts the conversion from 111110000001100100111111100101110001111110 to pqavnbcp. v Sample Case 1 Sample Input a 100100 b. 100101 110001 d. (newline] 100000 111111 100100111111100101110001100000 Sample Output a bcd Explanation encoded: 100100111111100101110001100000 Character Code a 100100 b 100101 100100 111111 100101 110001 108000 110001 a \n 100000 Inewline] 111111 decoded: a\nbcd This diagram depicts the conversion from 100100111111100101110001100000 to a\nbcd. string decode (vector<string> codes, string encoded) {
Expert Answer:
Related Book For
Business Analytics Data Analysis and Decision Making
ISBN: 978-1305947542
6th edition
Authors: S. Christian Albright, Wayne L. Winston
Posted Date:
Students also viewed these mathematics questions
-
An array comprises two dipoles that are separated by one wavelength. If the dipoles are fed by currents of the same magnitude and phase, (a) Find the array factor. (b) Calculate the angles where the...
-
Value stream mapping involves first developing a baseline map of the current situation of a companys external and/ or internal operations, and then applying lean concepts, and developing a future...
-
If X and Y are mappings on ( into (, show that Where Q is the set of rationals in (. re
-
Upon graduation from high school, John Abel immediately accepted a job as an electrician's assistant for a large local electrical repair company. After three years of hard work, John received an...
-
a. Through what programs has the IRS gathered data to develop its DIF statistical models? b. How do these programs differ? c. How has the IRS used these programs to select returns for audit?
-
Paul and Karen Kent are married, and both are employed (Paul earned $44,000 and Karen earned $9,000 this year). Paul and Karen have two dependent children, Samuel and Joy, both under the age of 13....
-
Consider the following investments: 1. $2,000 at the end of each of the next five years at 10 percent interest compounded annually. ' 2. $12,000 at the end of each of the next eight years at 4...
-
Waters Hardware Store completed the following merchandising transactions in the month of May. At the beginning of May, Waters ledger showed Cash of $8,000 and Common Stock of $8,000. May 1 Purchased...
-
Country factor timing and nepotism Your analyst gives you the following information on three interest-rate sensitive securities that are correctly priced according to a 2-factor model, rA = 1.5 f1...
-
Presented here are summarized data from the balance sheets and income statements of Wiper Inc.: Required: a. Calculate return on investment, based on net income and average total assets, for 2023 and...
-
In the last two times around the board, Wes thought he was a goner. First, he had to pay half of his money in rent to somebody. He then had to pay $25. Because of a Chance card after that he landed...
-
Fill in the Blank. In real-time frequency analysis, the signal is continuously analyzed over all the ___________ bands.
-
Fill in the Blank. The ____________ energy of a beam is denoted by \(\frac{1}{2} \int_{0}^{l} ho A\left(\frac{\partial w}{\partial t} ight)^{2} d x\).
-
Fill in the Blank. The ____________ energy of a beam is denoted by \(\frac{1}{2} \int_{0}^{l} E I\left(\frac{\partial^{2} w}{\partial x^{2}} ight)^{2} d x\).
-
An external torque \(M_{t}(t)=M_{t 0} \cos \omega t\) is applied at the free end of a fixed-free uniform shaft. Find the steady-state vibration of the shaft.
-
a. Zero bending moment b. Zero transverse displacement c. Zero shear force d. Zero slope \(W^{\prime \prime \prime}=0\)
-
Meadow Dew Corporation actualmente tiene un EPS de $ 4.05 y elPE de referencia para la empresa es 21. Se espera que las gananciascrezcan un 4.9 por ciento por ao. a. Cul es su estimacin del 1 answer
-
A firm has the following balance sheet: Assets Cash Accounts receivable Inventory Plant and equipment $ 15,000 150,000 92,000 170,000 $427,000 Liabilities and Equity Accounts payable Long-term debt...
-
A sportswriter wants to know how strongly the residents of Indianapolis, Indiana, support the local minor league baseball team, the Indianapolis Indians. He stands outside the stadium before a game...
-
How much influence can the employee requirements for one, two, or three days have on the weekly schedule in the employee scheduling example? You are asked to explore this in the following questions....
-
In the RedBrand example, suppose the plants cannot ship to each other and the customers cannot ship to each other. Modify the model appropriately, and rerun Solver. How much does the total cost...
-
Using divisibility rules, determine if 342,887 is divisible by 9 .
-
Using divisibility rules, determine if 87,762 is divisible by 10 .
-
Can 43,568 pieces of mail be separated into 6 bins with the same number of pieces of mail per bin?
Study smarter with the SolutionInn App