1. Engineering
  2. Computer Science
  3. java 8...

Question: java 8...

Question details

Java 8

☆ The Huffman Decoder 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-ra 100100, b 100101Xnewline] 1 1 11 11) and the string encoded-1001001 1 1 1 1 1 100101 we do the following Break encoded into its constituent encodings. 100180 100181 Now map them to their characters and return the string: ainb. This will print as: Note: While all code mappings in the example are 6 digits long, mappings can be different lengths. The algorithm creates the shortest length mapping for the most frequent character encoded. Function Description Complete the function decode in the editor below. The function must return the decoded string decode has the following parameterfs): codesícodesfo1...codesn-11: an array of character mappings encoded: an encoded string

Constraints 1sns100 All characters of encoded are either 0 or All inputs will represent a valid Huffman encoded string 1 s lencoded]s 7000 1 ▼ Input Format for Custom Testing Input from stdin will be processed as follows and passed to the function The first line contains an integer n, the size of the array codes Each of the next n lines contains a tab-separated character/mapped code pair codesi. The last line contains an encoded string encoded. Sample Case 0 Sample Input 180100 180101 110001 180000 Inewline] 80001 8101110001111

Sample Output pqa bcp Explanation encoded Code 100100 180101 Character 10 11110 0000 100100 1111 100102 1101 1110 100000 decoded 0e0001 This diagram depicts the conversion from 111110000001100100111111100101110001111110 to pqalnbcp

Sample Case 1 Sample Input 100108 100101 110001 180008 Inewline] 8011880 Sample Output bcd Explanation 01110001180 800 Character 180180 100101 110001 180000 180101 110801 180800 Ln decoded alnbed This diagram depicts the conversion from 100100111111100101110001100000 to anbcd.

YOUR ANSWER Draft saved 02:12 pm Original Code Java 8 1 import java.io. 14 15 class Result 16 17 18 19 20 21 Complete the decode function below *The function is expected to return a STRING The function accepts following parameters: *1. STRING ARRAY codes 23 24 25 2 STRING encoded public static String decode(List<String> codes, String encoded) ( // Write your code here 27 28 29 30 31 32 33 public class Solution {

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution