Burrows-Wheeler transform

The Burrows-Wheeler transform (also known as block-sorting compression) is an algorithm used in data compression techniques. A string transform, it acts on its input to produce a string that is (for many inputs) more easily compressed, due to long runs of identical characters (which may be effectively compressed by, for instance, run length encoding).

Example
TODO

Definition
The following pseudocode illustrates a naive version of the algorithm and its inverse. It assumes that the last character of s is EOF.

function BWT(string s) { Append the EOF character to s.     Create a table T comprised of all cyclic rotations of s.      Sort T lexicographically. Return the string given by the last column of T. }

function inverseBWT(string s) { Initialize a table T with s as the only column. for i = 0 to |s| - 1 { Add s as the first column of T.         Sort the rows of T in lexicographic order. }     Return the row with the EOF character in the last position. }

The intuition behind the inverse transform is as follows. Suppose we are given b = BWT(s). Our goal is to reconstruct the sorted cyclic rotation table T used in the BWT algorithm. The last column is trivially given by b. Since T has the property of being sorted, and b contains all characters in the original string, we can obtain the first column of T by sorting b.  This leaves us with all pairs of adjacent characters in any cyclic rotation of s.  We obtain all triplets by adding b as the first column of the table and sorting again, and so on. Once T is constructed, we choose the unique row that containing the EOF character in its last position. This is the original string s.

Optimizations
TODO

Performance
TODO