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

FrequecyTester.java class MinHeap{ // array storing items in the min-heap int[]

ID: 3701969 • Letter: F

Question

FrequecyTester.java

class MinHeap{
// array storing items in the min-heap
int[] arr;
int size; // heap size
  
public MinHeap(int MAXSIZE){
// construct an array and set the size to 0
arr = new int[MAXSIZE];
size = 0;
}

public int min(){
// return the minimum value in the heap
return arr[0];
}

public int removeMin(){
// return and remove the minimum value
int result = arr[0];
arr[0] = arr[size - 1];
size--;
downHeap(0);

return result;
}

public void upHeap(int index){
int parentIndex = (index - 1) / 2;
int temp;
while (parentIndex >= 0 && arr[parentIndex] > arr[index]){
temp = arr[index];
arr[index] = arr[parentIndex];
arr[parentIndex] = temp;
index = parentIndex;
parentIndex = (index - 1) / 2;
}
}

public void downHeap(int index){
boolean done = false;
int temp, leftIndex, rightIndex, targetIndex;

while (!done){
leftIndex = 2*index + 1 ;
rightIndex = 2*index + 2;
if (leftIndex >= size){
done = true;
} else {
targetIndex = leftIndex;
if (rightIndex < size && arr[rightIndex]<arr[leftIndex]){
targetIndex = rightIndex;
}
if (arr[index]<=arr[targetIndex]){
done = true;
} else {
temp = arr[index];
arr[index] = arr[targetIndex];
arr[targetIndex] = temp;
index = targetIndex;
}
}
}
}

public void insert(int value){
// insert a new value in the heap
arr[size] = value;
upHeap(size);
size++;
}

public void printArray(){
// print the array representation of the heap
for (int i=0; i<size; i++)
System.out.print(arr[i]+" ");
System.out.println();
}
}

FrequencyList.java

Its to be in java language

smallest.txt
hello there, how are you? I am fine. Thank you.

COMP-2 14 ?'D Priority aeues and HumxM, cheggcom anitoba.desire2learn.com/content/enforced3/266657-50140.201810/Assignments/a5/a5-comp2140-2018.pdf COMP 2140 Assignment 5 Huffman Coding Pak Ching Li Due: Friday April 6, 2018-11:59 PM (Last Day of Classes) Programming Standards When writing code for this course, follow the progrataning standards, available on this course's website on UMLearn. Failure to do so will result in the loss of marks Objective In this assignment, yon will use binary trees and heaps to implement the Huffman coding scheme Your Program General Overview: In this assignment, your task is to implement the enckling and decoding algorithms for Hufima? coding. Huffinan coding will be discussed in class aud therefore we will not spend much time talking about how the algorithis work There are three major steps to the solution that needs to be dealt with 1. Reading in a data file and computing the frequeney of characters. 2. Using these frequencies, build an Huffman eacoiling tree and ecode the dats file using it 3. Using the encoding of the data tile and the Hutfmian tree, decude to ohtai? origiual data file Important: Before you go any furthet, you should go through the slides Erom the ueture notes ou Huffinan coding and have them handy as you are resding the tust of tho assignt 1-Reading Data File and Frequency Computation In this step, you are to proampt for a text data file, open it and coaupute (udl store) the frequesicy of each character tiat oceutS TO help you mouuputing the f e lumnes, a Net onalpe ?s… the hle PrequencyLtet , java is provided that will do thus for yoni Thest classes will create a linked list where esaclh node s data coasists of a cha

Explanation / Answer

Answer: See code to prepare frequency list below

----------------------------------------

package huffmancoding;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
* HuffmanCodingDemo class
*
*/
public class HuffmanCodingDemo {

   /**
   * @param args
   * @throws IOException
   */
   public static void main(String[] args) throws IOException {
       String filename; //name/path of file containing data
       final int MAX_LINES = 100; //maximum number of possible lines in data file
       String[] data = new String[MAX_LINES];
       int numLines = 0; //actual number of lines in data file
      
       //read name/path of file containing data
       System.out.println("Please enter path of file:");
       BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       filename = reader.readLine();
       reader.close();
       System.out.println("Data file:"+filename);
      
       //read data from file
       File file = new File(filename);
       BufferedReader reader2 = new BufferedReader(new FileReader(file));
       String line;
       int i = 0; //counter
       while ((line=reader2.readLine())!=null)
       {
           line = line+" "; //adds newline character at the end of line
           data[i] = line;
           i++;
       }
       numLines = i; //number of lines in data file
      
       //create Frequency List of data
       FrequencyList frequencyList = new FrequencyList();
       for(i = 0; i < numLines; i++)
       {
           line = data[i];
           for(int j =0; j<line.length(); j++)
           {
               frequencyList.insert(String.valueOf(line.charAt(j)));
           }
       }
      
       //print frequency list
       frequencyList.printList();
   }

}

---------------------------------------

Note: Under FrequencyTester.hava, wrong code is given.

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