title: Big O complexities of my Huffman Algorithm
body: <p>Can someone please tell me the Space and time Complexities, in Bog O notation, of this Huffman code with a little explanation. Would be very much appreciated, thanks. And please do mention the Big O of each method separately, would be great. Thanks.</p>
  
  <pre><code>package HuffmanProject;
  
  import java.util.*;
  
  class MyHCode {
  public static void main(String[] args) {
  String test = "My name is Zaryab Ali";
  int[] FreqArray = new int[256];
  
  for (char c : test.toCharArray()) {
  FreqArray[c]++;
          }
  MyHTree tree = ImplementTree(FreqArray);
  
  System.out.println("CHARACTER\tFREQUENCY\tBINARY EQUIVALEENT CODE");
  PrintMyHCode(tree, new StringBuffer());
      }
  
  public static MyHTree ImplementTree(int[] FreqArray) {
  PriorityQueue&lt;MyHTree&gt; trees = new PriorityQueue&lt;MyHTree&gt;();
  
  for (int i = 0; i &lt; FreqArray.length; i++) {
  if (FreqArray[i] &gt; 0) {
  trees.offer(new MyHLeaf(FreqArray[i], (char) i));
              }
          }
  while (trees.size() &gt; 1) {
  MyHTree FChild = trees.poll();
  MyHTree SChild = trees.poll();
  trees.offer(new MyHNode(FChild, SChild));
          }
  return trees.poll();
      }
  
  public static void PrintMyHCode(MyHTree tree, StringBuffer prefix) {
  
  if (tree instanceof MyHLeaf) {
  MyHLeaf leaf = (MyHLeaf) tree;
  System.out.println(leaf.CharValue + "\t\t" + leaf.frequency + "\t\t" + prefix);
  } 
  else if (tree instanceof MyHNode) {
              MyHNode node = (MyHNode) tree;
  
              prefix.append('0');
              PrintMyHCode(node.left, prefix);
              prefix.deleteCharAt(prefix.length() - 1);
  
              prefix.append('1');
              PrintMyHCode(node.right, prefix);
              prefix.deleteCharAt(prefix.length() - 1);
          }
      }
  
  
  }
  abstract class MyHTree implements Comparable&lt;MyHTree&gt; {
  public int frequency;
  
  public MyHTree(int f) {
          frequency = f;
      }
  
  public int compareTo(MyHTree tree) {
          return frequency - tree.frequency;
      }
  }
  
  class MyHLeaf extends MyHTree {
  public char CharValue;
  
  public MyHLeaf(int f, char v) {
          super(f);
          CharValue = v;
      }
  }
  
  class MyHNode extends MyHTree {
  public MyHTree left, right;
  
  public MyHNode(MyHTree l, MyHTree r) {
          super(l.frequency + r.frequency);
          left = l;
          right = r;
      }
  }
  </code></pre>