Java, I need extractCodes, encode, write files, and build tree implemented. Everything you need is included. Do not use

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Java, I need extractCodes, encode, write files, and build tree implemented. Everything you need is included. Do not use

Post by answerhappygod »

Java, I need extractCodes, encode, write files, and build tree implemented. Everything you need is included. Do not use a premade solution as it will not match with the given API. you will receive an automatic thumbs down if deemed so.
Java I Need Extractcodes Encode Write Files And Build Tree Implemented Everything You Need Is Included Do Not Use 1
Java I Need Extractcodes Encode Write Files And Build Tree Implemented Everything You Need Is Included Do Not Use 1 (149.24 KiB) Viewed 49 times
Java I Need Extractcodes Encode Write Files And Build Tree Implemented Everything You Need Is Included Do Not Use 2
Java I Need Extractcodes Encode Write Files And Build Tree Implemented Everything You Need Is Included Do Not Use 2 (176.39 KiB) Viewed 49 times
Java I Need Extractcodes Encode Write Files And Build Tree Implemented Everything You Need Is Included Do Not Use 3
Java I Need Extractcodes Encode Write Files And Build Tree Implemented Everything You Need Is Included Do Not Use 3 (150.53 KiB) Viewed 49 times
Java I Need Extractcodes Encode Write Files And Build Tree Implemented Everything You Need Is Included Do Not Use 4
Java I Need Extractcodes Encode Write Files And Build Tree Implemented Everything You Need Is Included Do Not Use 4 (119.78 KiB) Viewed 49 times
Formal Specifications MyOrderedList<Type extends Comparable<Type>> +binarySearch(item : Type) : Type -binarySearch(item : Type, int start, int finish) : Type +get(index : int) : Type Method summary binarySearch - Upgrade this method to return the item searched for. This is common when that item contains other data that we want. Our HuffmanEncoder will need this functionality to find nodes based on the character stored in them. • get - Returns the element stored at index and null if the index is out of bounds. This method should run in O(1) time. - HuffmanEncoder -inputFileName : String -outputFileName : String -codesFileName : String -book : BookReader -frequencies : MyOrderedlist<FrequencyNode> - huffman Tree : HuffmanNode -codes : MyOrderedList<CodeNode> -encodedText : byte[] +HuffmanEncoder() -countFrequency() -buildTree() -extractCodes (root : HuffmanNode, code : String) -encode() -writeFiles() Field summary inputFileName - filename for the uncompressed input file For testing default to “./WarAndPeace.txt". • outputFileName - filename for the compressed output file o
o . O . For testing should be set to "/WarAndPeace-compressed.bin". codesFileName - filename for the codes output file For testing should be set to "/WarAndPeace-codes.txt". book - A book reader initialized with the inputFileName. • frequencies - A list that stores the frequency of each character in the input file. huffman Tree - The root of the Huffman tree. • codes - A list that stores the codes assigned to each character by the Huffman algorithm. • encodedText - The encoded binary string stored as an array of bytes. . . o O o . o o Method summary HuffmanEncoder - The constructor should call the helper methods in the correct order to carry out Huffman's algorithm. • countFrequency - This method counts the frequency of each character in the book and stores it in frequencies. Iterate through the text character by character maintaining counts in frequencies. The counts are stored in FrequencyNodes. It should output the time it takes to count the frequencies. buildTree - This method builds the Huffman tree and extracts the codes from it, storing them in codes. It does so by carrying out these steps: Create a single Huffman node for each character weighted by its count. Add all the nodes to a priority queue. Merge Huffman nodes until only a single tree remains. Store the root of the remaining tree in huffman Tree. Extract the codes from the tree and store them in codes using the recursive helper function like this: extractCodes(huffman Tree, ""); It should output the time it takes to build the tree and extract the codes. extractCodes - A recursive method that traverses the Huffman tree to extract the codes stored in it. This method will conduct a recursive depth-first traversal of the Huffman tree. The path of left and right moves is stored in the code parameter by adding “O" for left traversals and "1" for right traversals. When a leaf is reached the code is stored in the codes list. encode - Uses the book and codes to create encodedText. For each character in text, append the code to an intermediate string. Convert the string of character into a list of bytes and store it in encoded Text. o O O o o o . o
o O You can convert a string of 'O's and '1's to a byte with this line: byte b = (byte)Integer.parseInt(str,2); It should output the time it takes to encode the text. writeFiles() - Writes the contents of encodedText to the outputFileName and the contents of codes to codesFileName. It should output the time it takes to write the files. - O FrequencyNode implements Comparable<FrequencyNode> +character : Character +count : Integer +compareTo(other : FrequencyNode) : int +toString() : String Field summary character - The character that this count is for. count - The count for this character. . . . Method summary compareTo - This method compares the nodes based on the character stored in them. toString - This method returns the contents of the node in this format: character:count . HuffmanNode implements Comparable<HuffmanNode> +character : Character +weight : Integer +left : HuffmanNode +right : HuffmanNode +HuffmanNode(ch : Character, wt : Integer) +HuffmanNode(left : HuffmanNode, right : HuffmanNode) +compareTo(other : HuffmanNode) : int +toString() : String Field summary character - The character that this node stores. Only leaves store characters.
. - Internal nodes have no characters. weight - The weight of the Huffman tree rooted at this node. • left - The root of the left sub-tree. right - The root of the right sub-tree. - - Method summary HuffmanNode. There are two constructors for Huffman nodes. The first is to create the initial leaf nodes. The second is used when merging two nodes. • compare To - This method compares the nodes based on the weight stored in them. • toString - This method returns the contents of the node in this format: character:weight - CodeNode implements Comparable<CodeNode> +character : Character +code : String +compareTo(other : CodeNode) : int +toString() : String Field summary character - The character that this node stores the code for. code - The code assigned to this character. - Method summary compareTo - This method compares the nodes based on the character stored in them. • toString - This method returns the contents of the node in this format: character:code
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply