Question: JAVA CODE: BinaryTree.java: public class BinaryTree { private T data; private BinaryTree parent; private BinaryTree left; private BinaryTree right; public BinaryTree(){ parent = left =

JAVA CODE:

JAVA CODE: BinaryTree.java: public class BinaryTree { private T data; private BinaryTreeparent; private BinaryTree left; private BinaryTree right; public BinaryTree(){ parent = left= right = null; data = null; } public void makeRoot(T data){if (!isEmpty()){ System.out.println("Can't make root. Already exists"); } else this.data = data;

BinaryTree.java:

public class BinaryTree { private T data; private BinaryTree parent; private BinaryTree left; private BinaryTree right; public BinaryTree(){ parent = left = right = null; data = null; } public void makeRoot(T data){ if (!isEmpty()){ System.out.println("Can't make root. Already exists"); } else this.data = data; } public void setData(T data){ this.data = data; } public void setLeft(BinaryTree tree){ left = tree; } public void setRight(BinaryTree tree){ right = tree; } public void setParent(BinaryTree tree){ parent = tree; } public T getData(){ return data; } public BinaryTree getParent(){ return parent; } public BinaryTree getLeft(){ return left; } public BinaryTree getRight(){ return right; } public void attachLeft(BinaryTree tree){ if (tree==null) return; else if (left!=null || tree.getParent()!=null){ System.out.println("Can't attach"); return; } else{ tree.setParent(this); this.setLeft(tree); } } public void attachRight(BinaryTree tree){ if (tree==null) return; else if (right!=null || tree.getParent()!=null){ System.out.println("Can't attach"); return; } else{ tree.setParent(this); this.setRight(tree); } } public BinaryTree detachLeft(){ if (this.isEmpty()) return null; BinaryTree retLeft = left; left = null; if (retLeft!=null) retLeft.setParent(null); return retLeft; } public BinaryTree detachRight(){ if (this.isEmpty()) return null; BinaryTree retRight = right; right =null; if (retRight!=null) retRight.setParent(null); return retRight; } public boolean isEmpty(){ if (data == null) return true; else return false; } public void clear(){ left = right = parent =null; data = null; } public BinaryTree root(){ if (parent == null) return this; else{ BinaryTree next = parent; while (next.getParent()!=null) next = next.getParent(); return next; } } public static  void preorder(BinaryTree t){ if (t!=null){ System.out.print(t.getData()+"\t"); preorder(t.getLeft()); preorder(t.getRight()); } } public static  void inorder(BinaryTree t){ if (t!=null){ inorder(t.getLeft()); System.out.print(t.getData() + "\t"); inorder(t.getRight()); } } public static  void postorder(BinaryTree t){ if (t!=null){ postorder(t.getLeft()); postorder(t.getRight()); System.out.print(t.getData() + "\t"); } } }

Pokemon.txt

POKEMON TOWER DEFENSEYOUR MISSION IN THIS FUN STRATEGY TOWER DEFENSE GAME IS TO HELP PROFESSOR OAK TO STOP ATTACKS OF WILD RATTATA SET OUT ON YOUR OWN POKEMON JOURNEY TO CATCH AND TRAIN ALL POKEMON AND TRY TO SOLVE THE MYSTERY BEHIND THESE ATTACKS YOU MUST PLACE POKEMON CHARACTERS STRATEGICALLY ON THE BATTLEFIELD SO THAT THEY STOP ALL WAVES OF ENEMY ATTACKER DURING THE BATTLE YOU WILL LEVEL UP AND EVOLVE YOUR POKEMON YOU CAN ALSO CAPTURE OTHER POKEMON DURING THE BATTLE AND ADD THEM TO YOUR TEAM USE YOUR MOUSE TO PLAY THE GAME GOOD LUCK
Frequency.txt  E 12.02 T 9.10 A 8.12 O 7.68 I 7.31 N 6.95 S 6.28 R 6.02 H 5.92 D 4.32 L 3.98 U 2.88 C 2.71 M 2.61 F 2.30 Y 2.11 W 2.09 G 2.03 P 1.82 B 1.49 V 1.11 K 0.70 X 0.17 Q 0.11 J 0.10 Z 0.07

Problem Summary: You are given a table of letters of the English alphabet and their frequencies. Build a Huffman tree with the alphabet symbols and their probabilities. Derive the Huffman codes. Using the codes, encode a given text file with the codes. Decode the encoded text file and show that it is the same as the input text file Problem in Detail: In order to help you with the assignment, here's the Huffman algorithm step-by-step procedure (as discussed in the lectures) Step 1: Read the text file frequency.txt. Its link is given next to this lab document. It contains the frequency of letters in the English alphabet based on a sample of 40,000 words as shown below. (The file actually contains each letter and its frequency on two separate lines) (Source: http://pi.math.cornell.edu/-mec/2003-2004/cryptography/subs/frequencies.html) E 12.02 T 9.10 A 8.12 0 7.68 7.31 N 6.95 S 6.28 R 6.02 H 5.92 D 4.32 L 3.98 U 2.88 2.71 M 2.61 F 2.30 Y 2.11 W 2.09 G 2.03 P 1.82 B 1.49 V 1.11 K 0.70 X 0.17 Q 0.11 J 0.10 Z 0.07 Problem Summary: You are given a table of letters of the English alphabet and their frequencies. Build a Huffman tree with the alphabet symbols and their probabilities. Derive the Huffman codes. Using the codes, encode a given text file with the codes. Decode the encoded text file and show that it is the same as the input text file Problem in Detail: In order to help you with the assignment, here's the Huffman algorithm step-by-step procedure (as discussed in the lectures) Step 1: Read the text file frequency.txt. Its link is given next to this lab document. It contains the frequency of letters in the English alphabet based on a sample of 40,000 words as shown below. (The file actually contains each letter and its frequency on two separate lines) (Source: http://pi.math.cornell.edu/-mec/2003-2004/cryptography/subs/frequencies.html) E 12.02 T 9.10 A 8.12 0 7.68 7.31 N 6.95 S 6.28 R 6.02 H 5.92 D 4.32 L 3.98 U 2.88 2.71 M 2.61 F 2.30 Y 2.11 W 2.09 G 2.03 P 1.82 B 1.49 V 1.11 K 0.70 X 0.17 Q 0.11 J 0.10 Z 0.07

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!