Give the result of encoding the string ab abab ababab ababab

Give the result of encoding the string ab, abab, ababab, abababab, ... (strings consisting of N repetitions of ab) with run-length, Huffman and LZW encoding. What is the compression ratio as a function of N?

Solution

public class BinaryDump
{
   public static void main(String[] args)
   {
      int width = Integer.parseInt(args[0]);
      int cnt;
      for (cnt = 0; !BinaryStdIn.isEmpty(); cnt++)
      {
         if (width == 0) continue;
         if (cnt != 0 && cnt % width == 0)
            StdOut.println();
         if (BinaryStdIn.readBoolean())
              StdOut.print(\"1\");
         else StdOut.print(\"0\");
      }
      StdOut.println();
      StdOut.println(cnt + \" bits\");
   }
}

Give the result of encoding the string ab, abab, ababab, abababab, ... (strings consisting of N repetitions of ab) with run-length, Huffman and LZW encoding. Wh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site