Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that performs Huffman coding and compression using a binary tree

ID: 3540422 • Letter: W

Question

Write a  program  that  performs  Huffman coding  and  compression  using  a  binary  tree.lang="en-us">


PDF that might tell the detail https://docs.google.com/file/d/0ByJxQ-A3ukD6ZXBJRklEdWgxVGM/edit?usp=sharinglang="en-us">


and here is the java file https://docs.google.com/file/d/0ByJxQ-A3ukD6a0h0cmtEdWtMcDg/edit lang="en-us">


it need to be look like this https://docs.google.com/file/d/0ByJxQ-A3ukD6R1hrZENieEdUUTg/edit?usp=sharing
lang="en-us">


Write a program that performs Huffman coding and compression using a binary tree.

Explanation / Answer

public class Huffman { // alphabet size of extended ASCII private static final int R = 256; // Huffman trie node private static class Node implements Comparable { private final char ch; private final int freq; private final Node left, right; Node(char ch, int freq, Node left, Node right) { this.ch = ch; this.freq = freq; this.left = left; this.right = right; } // is the node a leaf node? private boolean isLeaf() { assert (left == null && right == null) || (left != null && right != null); return (left == null && right == null); } // compare, based on frequency public int compareTo(Node that) { return this.freq - that.freq; } } // compress bytes from standard input and write to standard output public static void compress() { // read the input String s = BinaryStdIn.readString(); char[] input = s.toCharArray(); // tabulate frequency counts int[] freq = new int[R]; for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote