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

Java : Can I have help with this problem? And you add comments Input: String X o

ID: 3604068 • Letter: J

Question

Java : Can I have help with this problem? And you add comments

Input: String X of length n with d distinct characters.

1. Compute the frequency of each character c of X. 2. Create a forest of single-node trees.

Each node in the initial forest represents a symbol from the set of possible symbols, and contains the count of that symbol in the message to be coded.

3. Loop while there is more than 1 tree in the forest:

Remove the two trees from the forest that have the lowest count contained in their roots.

Create a new node that will be the root of a new tree. This new tree will have those two trees just removed in step above as left and right subtrees. The count in the root of this new tree will be the sum of the counts in the roots of its subtrees.

Insert this new tree in the forest, and go to step 3.

3.1 Each step of the algorithm reduces the number of trees in the forest by one; It terminates when there is only one tree. 4. Return the tree in the forest as the Huffman code tree.

Explanation / Answer

import java.util.*;   public class TreeMapExample {      public static void main(String args[]) {      // Create and populate tree map      Map map = new TreeMap();               map.put(102,"Let us C");      map.put(103, "Operating System");      map.put(101, "Data Communication and Networking");      System.out.println("Values before remove: "+ map);        // Remove value for key 102      map.remove(102);      System.out.println("Values after remove: "+ map);      }       }
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