Writing Algorithm Java Code Construct Code Tree Huffman Algorithm Alphabet Symbols B C D E Q37105881

Writing Algorithm and Java Code

Construct the code tree of the Huffman algorithm forthe alphabet of the symbols
{b, c, d, e, f, g} with the following probabilities {0.05, 0.1,0.15, 0.35, 0.2, 0.15}.

Thanks Sir.


Solution


//Your java Code

import java.util.PriorityQueue;
import javafx.util.Pair;
import java.util.Scanner;
import java.util.Comparator;
class node{//Node of huffman trees
   char ch;
   node left;
   node right;
}
class MyComparator implements Comparator<Pair<Double,node>> { //comaparator function
    public int compare(Pair<Double,node> x,Pair<Double,node> y)
    {
   if((x.getKey()) > (y.getKey()))
        return 1;
   else
   return -1;
    }
}
public class HuffmanTree{
      public static void printCode(node root,String s) { //to print your codes for each character
       if (root.left == null&&root.right == null&& Character.isLetter(root.ch)) {
  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.