Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

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

FrequencyList.java

class FrequencyList { Node head; int count; FrequencyList() { head = null; count = 0; } //search for node in linked list that contains key. Returns a reference to node if found, else returns null. public Node search(String key) { Node curr=head; while (curr != null) { if (key.compareTo(curr.data.symbol) == 0) { break; } curr = curr.next; } return curr; } //print contents of linked list. public void printList() { Node curr; curr = head; while (curr != null) { //print each node curr.print(); curr = curr.next; } } //insert a new node if key is not in the linked list. Otherwise increment frequency by 1. public void insert(String key) { Node curr; curr = search(key); if (curr == null) { //key not in list, add it to front. curr = new Node(key); //insert new node at front of list curr.next = head; head = curr; count = count + 1; } else { //already in list. Increment the frequency by 1. curr.data.frequency = curr.data.frequency + 1; //increment frequency of symbol } } } //A node of the Linked List class FrequencyList. class Node { FrequencyData data; Node next; Node(String key) { data = new FrequencyData(key,1); } void print() { data.print(); } } //This class contains a symbol and its frequency class FrequencyData { String symbol; //using a string type will become handy when build the Huffman encoding tree. int frequency; FrequencyData (FrequencyData data) { symbol = data.symbol; frequency = data.frequency; } FrequencyData(String s, int freq) { symbol = s; frequency = freq; } //print content of symbol (which may contain more than one character //for debugging purposes only. void printSymbol() { int i; int a; String s=""; for (i = 0; i "; //instead of printing a newline, print  instead else if (a == 32) s =s+""; //same for space else if (a == 9) s =s+""; //same for tab. Should probably do same for "escaped" characters else s = s+ symbol.charAt(i); } System.out.print(s); } /*used to print symbol(s) and frequency*/ /*used for debugging*/ void print() { printSymbol(); System.out.println(":"+frequency); } } 

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Why We Form Relationships Managing Relationship Dynamics?

Answered: 1 week ago