QuestionQuestion

Write a program that takes any input text and produces both a frequency table and the corresponding Huffman code.
1. Take approximately 360 words from any English document as your input text. Ignore all blanks, all punctuation marks, all special symbols. Create an input file with this input text.
2. Construct the frequency table according to the input text read from the file:
1. The frequency's must be listed, in order, from largest (at the top) to smallest (at the bottom)
3. Then, using the Huffman algorithm, construct the optimal prefix binary code for the table.
1. The Huffman codes will be sorted in the same manner as the one above i.e. frequency, highest to lowest.
4. Design your program to read the input from the input file "infile.dat". Your program must produce the output, in the file "outfile.dat",(Files must be named "infile.dat" and "outfile.dat" consisting of
1. the frequency table for the source text,
2. the Huffman code for each letter and digit in the source code, and
3. the length of the coded message in terms of number of bits,
Final Output (Example Values Not Accurate)

Symbol Frequency
A, 15%
m, 11%
7, 6%

Symbol Huffman Codes
A,        10101
m,        1101
7,          111
Total Bits: 16005

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.io.*;
import java.text.DecimalFormat;
import java.util.*;

public class Huffman {

    // Node of the huffman tree
    class Node{
       int freq;
       char ch;
       Node left;
       Node right;
    }

    // This compares each node frequency
    class HuffmanComparator implements Comparator<Node> {
       public int compare(Node x, Node y)
       {
            return x.freq - y.freq;
       }
    }

    private Map<Character, Integer> huffMan;
    private String validChars = "abcdefghijklmnopqrst01234567890";
    private int total = 0;
    private int totalBits = 0;
    List<Map.Entry<Character, Integer>> list;
    List<Map.Entry<Character, String>> listCodes;

    public Huffman(){
       huffMan = new HashMap<>();
    }...

By purchasing this solution you'll be able to access the following files:
Solution.java.

$25.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats