Question: implements k-ary Huffman coding, which extends the standard binary Huffman coding algorithm. You will write four separate programs (count.cpp, build.cpp, encode.cpp, and decode.cpp) as described

 implements k-ary Huffman coding, which extends the standard binary Huffman coding

implements k-ary Huffman coding, which extends the standard binary Huffman coding algorithm. You will write four separate programs (count.cpp, build.cpp, encode.cpp, and decode.cpp) as described below. It is sufficient to implement arities ke 2 through 10 for full credit, and optionally you may also implement arities k 11 through 36 for extra credit The count.cpp program reads a source file and counts the number of appearances of each printable character (ASCII 32 through 126) that occurs in the text. It outputs a list of each such character's ASCI value and number of appearances (frequency), in ascending order by ASCI value. Do not output any control characters, or any character that does not occur within the text. Usage source.txt freq.txt The build.cpp program reads the arity k (an integer from 2 to 36) and the frequency data generated by the count.cpp program. It creates a k-ary Huffman tree (see explanation below), and outputs a list of each character's ASCII value and k-ary Huffman code, in ascending lexicographical order of the Huffman code strings. It also outputs the nodes of the Huffman tree in the order visited during a preorder traversal. Leaf nodes are displayed as L:xoxx where xxx is the ASCII value. Internal nodes are displayed as?: xxx, where each internal node is assigned a unique label xoox when it is created, starting with 256 and incrementing for each subsequent node. Also, to guarantee that the Huffman tree is unique in case of nodes having the same frequency, your heap should break ties by giving preference to nodes with smaller xoxx values. Usage: /build k freq.txt code.txt tree.txt The k-ary Huffman tree generalizes the standard binary Huffman tree, such that each internal node has exactly k children. If n is the number of leaves, then a k-ary tree can exist only when (n-1) is a multiple of (k-1), so if this condition is not true initially, then add sufficiently many extra leaves each having frequency 0 to make the condition true. Assign each extra leaf a unique ASCII value, starting with 128 and incrementing for each subsequent leaf The kary Huffman code generalizes the standard binary Huffman code It labels the child links using digits in base k. Each digit is represented as either a numeral (0 to 9) or a lowercase letter (?. 10, b. 11, c. 12, , z. 35). Example: wt en k16, use hexadeamal digits 0123456789abcdef The encode.cpp program reads the k-ary Huffman codes produced by build.cpp, and the source file to be encoded. It encodes the source file by replacing each non-control character with its corresponding k-ary Huffman code, and then it outputs the encoded text file. Usage: Jencode code.txt source.txt result.txt The decode.cpp program reads the arity k, the preorder traversal generated by the build.cpp program, and the encoded source file to be decoded. It uses the preorder traversal to re-build the k-ary Huffman tree, and then it uses this Huffman tree to decode the encoded text file. Finally it outputs the decoded plain text, which should exactly match the original source file that was encoded. Usage: decode k tree.txt result.txt source.txt implements k-ary Huffman coding, which extends the standard binary Huffman coding algorithm. You will write four separate programs (count.cpp, build.cpp, encode.cpp, and decode.cpp) as described below. It is sufficient to implement arities ke 2 through 10 for full credit, and optionally you may also implement arities k 11 through 36 for extra credit The count.cpp program reads a source file and counts the number of appearances of each printable character (ASCII 32 through 126) that occurs in the text. It outputs a list of each such character's ASCI value and number of appearances (frequency), in ascending order by ASCI value. Do not output any control characters, or any character that does not occur within the text. Usage source.txt freq.txt The build.cpp program reads the arity k (an integer from 2 to 36) and the frequency data generated by the count.cpp program. It creates a k-ary Huffman tree (see explanation below), and outputs a list of each character's ASCII value and k-ary Huffman code, in ascending lexicographical order of the Huffman code strings. It also outputs the nodes of the Huffman tree in the order visited during a preorder traversal. Leaf nodes are displayed as L:xoxx where xxx is the ASCII value. Internal nodes are displayed as?: xxx, where each internal node is assigned a unique label xoox when it is created, starting with 256 and incrementing for each subsequent node. Also, to guarantee that the Huffman tree is unique in case of nodes having the same frequency, your heap should break ties by giving preference to nodes with smaller xoxx values. Usage: /build k freq.txt code.txt tree.txt The k-ary Huffman tree generalizes the standard binary Huffman tree, such that each internal node has exactly k children. If n is the number of leaves, then a k-ary tree can exist only when (n-1) is a multiple of (k-1), so if this condition is not true initially, then add sufficiently many extra leaves each having frequency 0 to make the condition true. Assign each extra leaf a unique ASCII value, starting with 128 and incrementing for each subsequent leaf The kary Huffman code generalizes the standard binary Huffman code It labels the child links using digits in base k. Each digit is represented as either a numeral (0 to 9) or a lowercase letter (?. 10, b. 11, c. 12, , z. 35). Example: wt en k16, use hexadeamal digits 0123456789abcdef The encode.cpp program reads the k-ary Huffman codes produced by build.cpp, and the source file to be encoded. It encodes the source file by replacing each non-control character with its corresponding k-ary Huffman code, and then it outputs the encoded text file. Usage: Jencode code.txt source.txt result.txt The decode.cpp program reads the arity k, the preorder traversal generated by the build.cpp program, and the encoded source file to be decoded. It uses the preorder traversal to re-build the k-ary Huffman tree, and then it uses this Huffman tree to decode the encoded text file. Finally it outputs the decoded plain text, which should exactly match the original source file that was encoded. Usage: decode k tree.txt result.txt source.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!