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 Bernoulli random variable describing whether three out of three molecules remain inside at time 1. Think about one or more molecules independently leaving a cell, each with probability 0.9 in a...
-
In the ring topology in Figure 1.7, what happens if one of the stations is unplugged? Figure 1.7 Repeater Repeater Repeater |Repeater Repeater Repeater
-
Consider the simple linear regression model fit to the copolyester viscosity data in Problem 2.14. Problem 2.14 Hsuie, Ma, and Tsai ("Separation and Characterizations of Thermotropic Copolyesters of...
-
The comparative balance sheet of Canace Products Inc. for December 31, 2016 and 2015, is as follows: The income statement for the year ended December 31, 2016, is as follows: Additional data obtained...
-
Anthony, a member, is a partner in the firm of PriceWaterhouseCoopers LLP . Antony discovered that Macy's Corp. has not reported cash sales that amount to over 5 0 % of the company's gross...
-
You are the brand manager for your favorite brand of clothing, food, vehicle, or other consumer product. Write a one-page branding statement summarizing your brand for your company's VP of Marketing....
-
Find the total mass of the wire with density p Then use arc length to find average density r(t) = 2 costi 2 + sintj + 3tk, p(x,y,z) = 2 Z (k 0), 0 t 2
-
Interpret computer solutions of linear programming problems.
-
Explain the strategic importance of process selection and the influence it has on the organization and its supply chain.
-
Compare the advantages and disadvantages of time-based and output-based pay systems.
-
Describe behavioral approaches to job design.
-
Define the terms mission and strategy and explain why they are important.
-
1 f(x) = e/ for x 0. 3 a. Choose the correct formula for P (X xo). (1) P (X xo) = 1 - e(-xo/3) (2) P (x xo)=1+e(-xo/3) (3) P (X xo) = 1 - (1/3)e(-x0/3) (4) P (X xo)=1+ (1/3)e(-x0/3) Formula (1) V b....
-
The following cost information was provided to you for analysis: September 12,000 Units Produced Costs: TIC TAC TOE TING August 10,000 P80,000 70.000 60.000 50,000 How much is the fixed cost per...
-
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...
-
Differentiate between tax compliance and tax planning.
-
Differentiate between an open transaction and a closed transaction.
-
What form(s) is (are) used to file an individuals income tax return?
Study smarter with the SolutionInn App