Compression (II) |
The fast growth of program sizes and amount of stored data raises the need for efficient compression algorithms. They can significantly reduce the amount of storage space. Also the ``Internet boom", still suppressed by slow links has big influence on new developments in this field.
One of the most modern methods is block sorting. Its first step performed on
the data is Burrows-Wheeler transform (BWT). The idea, used by the authors,
comes from well-established in image compression Fourier transform and it says:
transform the data to the form which is easier to compress and then
compress it using one of the well-known algorithms.
Let's assume that as input we have a character string S of length N. The
first step of the transform is to generate from string S, N
strings S0, S1, ..., SN-1 in the following way:
The example that illustrates this algorithm is shown below:
S0 | P | A | S | C | A | L |
S1 | A | S | C | A | L | P |
S2 | S | C | A | L | P | A |
S3 | C | A | L | P | A | S |
S4 | A | L | P | A | S | C |
S5 | L | P | A | S | C | A |
In the second step all the strings are sorted to give:
S4 | A | L | P | A | S | C |
S1 | A | S | C | A | L | P |
S3 | C | A | L | P | A | S |
S5 | L | P | A | S | C | A |
S0 | P | A | S | C | A | L |
S2 | S | C | A | L | P | A |
The results of the transform, which are used in further work are:
It appears that such data are easier to perform an inverse transform and easier to compress by other methods than original input data.
Your task is to write a program, which performs above-described BWT transform on input string.
6 pascal
1 cpsala