<s>
The	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
(	O
BWT	O
,	O
also	O
called	O
block-sorting	B-Algorithm
compression	I-Algorithm
)	O
rearranges	O
a	O
character	O
string	O
into	O
runs	O
of	O
similar	O
characters	O
.	O
</s>
<s>
This	O
is	O
useful	O
for	O
compression	O
,	O
since	O
it	O
tends	O
to	O
be	O
easy	O
to	O
compress	O
a	O
string	O
that	O
has	O
runs	O
of	O
repeated	O
characters	O
by	O
techniques	O
such	O
as	O
move-to-front	B-Algorithm
transform	I-Algorithm
and	O
run-length	B-Algorithm
encoding	I-Algorithm
.	O
</s>
<s>
The	O
BWT	O
is	O
thus	O
a	O
"	O
free	O
"	O
method	O
of	O
improving	O
the	O
efficiency	O
of	O
text	B-General_Concept
compression	I-General_Concept
algorithms	O
,	O
costing	O
only	O
some	O
extra	O
computation	O
.	O
</s>
<s>
The	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
is	O
an	O
algorithm	O
used	O
to	O
prepare	O
data	O
for	O
use	O
with	O
data	B-General_Concept
compression	I-General_Concept
techniques	O
such	O
as	O
bzip2	B-Application
.	O
</s>
<s>
The	O
algorithm	O
can	O
be	O
implemented	O
efficiently	O
using	O
a	O
suffix	B-Algorithm
array	I-Algorithm
thus	O
reaching	O
linear	O
time	O
complexity	O
.	O
</s>
<s>
When	O
a	O
character	O
string	O
is	O
transformed	O
by	O
the	O
BWT	O
,	O
the	O
transformation	O
permutes	B-Algorithm
the	O
order	O
of	O
the	O
characters	O
.	O
</s>
<s>
The	O
transform	O
is	O
done	O
by	O
sorting	B-Algorithm
all	O
the	O
circular	B-Algorithm
shifts	I-Algorithm
of	O
a	O
text	O
in	O
lexicographic	O
order	O
and	O
by	O
extracting	O
the	O
last	O
column	O
and	O
the	O
index	O
of	O
the	O
original	O
string	O
in	O
the	O
set	O
of	O
sorted	O
permutations	B-Algorithm
of	O
S	O
.	O
</s>
<s>
Given	O
an	O
input	O
string	O
S	O
=	O
^BANANA|	O
(	O
step	O
1	O
in	O
the	O
table	O
below	O
)	O
,	O
rotate	O
it	O
N	O
times	O
(	O
step	O
2	O
)	O
,	O
where	O
N	O
=	O
8	O
is	O
the	O
length	O
of	O
the	O
S	O
string	O
considering	O
also	O
the	O
symbol	O
^	O
representing	O
the	O
start	O
of	O
the	O
string	O
and	O
the	O
red	O
|	O
character	O
representing	O
the	O
'	O
EOF	B-Language
 '	O
pointer	O
;	O
these	O
rotations	O
,	O
or	O
circular	B-Algorithm
shifts	I-Algorithm
,	O
are	O
then	O
sorted	O
lexicographically	O
(	O
step	O
3	O
)	O
.	O
</s>
<s>
The	O
following	O
pseudocode	B-Language
gives	O
a	O
simple	O
(	O
though	O
inefficient	O
)	O
way	O
to	O
calculate	O
the	O
BWT	O
and	O
its	O
inverse	O
.	O
</s>
<s>
It	O
assumes	O
that	O
the	O
input	O
string	O
s	O
contains	O
a	O
special	O
character	O
'	O
EOF	B-Language
 '	O
which	O
is	O
the	O
last	O
character	O
and	O
occurs	O
nowhere	O
else	O
in	O
the	O
text	O
.	O
</s>
<s>
Sorting	B-Algorithm
the	O
rotations	O
of	O
this	O
text	O
will	O
group	O
rotations	O
starting	O
with	O
"	O
he	O
"	O
together	O
,	O
and	O
the	O
last	O
character	O
of	O
that	O
rotation	O
(	O
which	O
is	O
also	O
the	O
character	O
before	O
the	O
"	O
he	O
"	O
)	O
will	O
usually	O
be	O
"	O
t	O
"	O
,	O
so	O
the	O
result	O
of	O
the	O
transform	O
would	O
contain	O
a	O
number	O
of	O
"	O
t	O
"	O
characters	O
along	O
with	O
the	O
perhaps	O
less-common	O
exceptions	O
(	O
such	O
as	O
if	O
it	O
contains	O
"	O
ache	O
"	O
)	O
mixed	O
in	O
.	O
</s>
<s>
Sorting	B-Algorithm
the	O
list	O
of	O
pairs	O
gives	O
the	O
first	O
and	O
second	O
columns	O
.	O
</s>
<s>
Then	O
,	O
the	O
row	O
with	O
the	O
"	O
end	B-Language
of	I-Language
file	I-Language
"	O
character	O
at	O
the	O
end	O
is	O
the	O
original	O
text	O
.	O
</s>
<s>
One	O
may	O
also	O
make	O
the	O
observation	O
that	O
mathematically	O
,	O
the	O
encoded	O
string	O
can	O
be	O
computed	O
as	O
a	O
simple	O
modification	O
of	O
the	O
suffix	B-Algorithm
array	I-Algorithm
,	O
and	O
suffix	B-Algorithm
arrays	I-Algorithm
can	O
be	O
computed	O
with	O
linear	O
time	O
and	O
memory	O
.	O
</s>
<s>
The	O
BWT	O
can	O
be	O
defined	O
with	O
regards	O
to	O
the	O
suffix	B-Algorithm
array	I-Algorithm
SA	O
of	O
text	O
T	O
as	O
(	O
1-based	O
indexing	O
)	O
:	O
</s>
<s>
There	O
is	O
no	O
need	O
to	O
have	O
an	O
actual	O
'	O
EOF	B-Language
 '	O
character	O
.	O
</s>
<s>
Instead	O
,	O
a	O
pointer	O
can	O
be	O
used	O
that	O
remembers	O
where	O
in	O
a	O
string	O
the	O
'	O
EOF	B-Language
 '	O
would	O
be	O
if	O
it	O
existed	O
.	O
</s>
<s>
The	O
algorithms	O
vary	O
somewhat	O
by	O
whether	O
EOF	B-Language
is	O
used	O
,	O
and	O
in	O
which	O
direction	O
the	O
sorting	B-Algorithm
was	O
done	O
.	O
</s>
<s>
In	O
fact	O
,	O
the	O
original	O
formulation	O
did	O
not	O
use	O
an	O
EOF	B-Language
marker	O
.	O
</s>
<s>
Since	O
any	O
rotation	O
of	O
the	O
input	O
string	O
will	O
lead	O
to	O
the	O
same	O
transformed	O
string	O
,	O
the	O
BWT	O
cannot	O
be	O
inverted	O
without	O
adding	O
an	O
EOF	B-Language
marker	O
to	O
the	O
end	O
of	O
the	O
input	O
or	O
doing	O
something	O
equivalent	O
,	O
making	O
it	O
possible	O
to	O
distinguish	O
the	O
input	O
string	O
from	O
all	O
its	O
rotations	O
.	O
</s>
<s>
Increasing	O
the	O
size	O
of	O
the	O
alphabet	O
(	O
by	O
appending	O
the	O
EOF	B-Language
character	O
)	O
makes	O
later	O
compression	O
steps	O
awkward	O
.	O
</s>
<s>
There	O
is	O
a	O
bijective	B-Algorithm
version	O
of	O
the	O
transform	O
,	O
by	O
which	O
the	O
transformed	O
string	O
uniquely	O
identifies	O
the	O
original	O
,	O
and	O
the	O
two	O
have	O
the	O
same	O
length	O
and	O
contain	O
exactly	O
the	O
same	O
characters	O
,	O
just	O
in	O
a	O
different	O
order	O
.	O
</s>
<s>
The	O
bijective	B-Algorithm
transform	O
is	O
computed	O
by	O
factoring	O
the	O
input	O
into	O
a	O
non-increasing	O
sequence	O
of	O
Lyndon	O
words	O
;	O
such	O
a	O
factorization	O
exists	O
and	O
is	O
unique	O
by	O
the	O
Chen	O
–	O
Fox	O
–	O
Lyndon	O
theorem	O
,	O
and	O
may	O
be	O
found	O
in	O
linear	O
time	O
.	O
</s>
<s>
The	O
algorithm	O
sorts	O
the	O
rotations	O
of	O
all	O
the	O
words	O
;	O
as	O
in	O
the	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
,	O
this	O
produces	O
a	O
sorted	O
sequence	O
of	O
n	O
strings	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
text	O
"	O
^BANANA|	O
"	O
is	O
transformed	O
into	O
"	O
ANNBAA^|	O
"	O
through	O
these	O
steps	O
(	O
the	O
red	O
|	O
character	O
indicates	O
the	O
EOF	B-Language
pointer	O
)	O
in	O
the	O
original	O
string	O
.	O
</s>
<s>
The	O
EOF	B-Language
character	O
is	O
unneeded	O
in	O
the	O
bijective	B-Algorithm
transform	O
,	O
so	O
it	O
is	O
dropped	O
during	O
the	O
transform	O
and	O
re-added	O
to	O
its	O
proper	O
place	O
in	O
the	O
file	O
.	O
</s>
<s>
(	O
Note	O
that	O
we	O
're	O
sorting	B-Algorithm
'	O
^	O
 '	O
as	O
succeeding	O
other	O
characters	O
.	O
)	O
</s>
<s>
The	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
can	O
indeed	O
be	O
viewed	O
as	O
a	O
special	O
case	O
of	O
this	O
bijective	B-Algorithm
transform	O
;	O
instead	O
of	O
the	O
traditional	O
introduction	O
of	O
a	O
new	O
letter	O
from	O
outside	O
our	O
alphabet	O
to	O
denote	O
the	O
end	O
of	O
the	O
string	O
,	O
we	O
can	O
introduce	O
a	O
new	O
letter	O
that	O
compares	O
as	O
preceding	O
all	O
existing	O
letters	O
that	O
is	O
put	O
at	O
the	O
beginning	O
of	O
the	O
string	O
.	O
</s>
<s>
The	O
whole	O
string	O
is	O
now	O
a	O
Lyndon	O
word	O
,	O
and	O
running	O
it	O
through	O
the	O
bijective	B-Algorithm
process	O
will	O
therefore	O
result	O
in	O
a	O
transformed	O
result	O
that	O
,	O
when	O
inverted	O
,	O
gives	O
back	O
the	O
Lyndon	O
word	O
,	O
with	O
no	O
need	O
for	O
reassembling	O
at	O
the	O
end	O
.	O
</s>
<s>
For	O
example	O
,	O
applying	O
the	O
bijective	B-Algorithm
transform	O
gives	O
:	O
</s>
<s>
When	O
a	O
text	O
is	O
edited	O
,	O
its	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
will	O
change	O
.	O
</s>
<s>
propose	O
an	O
algorithm	O
that	O
deduces	O
the	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
of	O
an	O
edited	O
text	O
from	O
that	O
of	O
the	O
original	O
text	O
,	O
doing	O
a	O
limited	O
number	O
of	O
local	O
reorderings	O
in	O
the	O
original	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
,	O
which	O
can	O
be	O
faster	O
than	O
constructing	O
the	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
of	O
the	O
edited	O
text	O
directly	O
.	O
</s>
<s>
This	O
Python	B-Language
implementation	O
sacrifices	O
speed	O
for	O
simplicity	O
:	O
the	O
program	O
is	O
short	O
,	O
but	O
takes	O
more	O
than	O
the	O
linear	O
time	O
that	O
would	O
be	O
desired	O
in	O
a	O
practical	O
implementation	O
.	O
</s>
<s>
It	O
essentially	O
does	O
what	O
the	O
pseudocode	B-Language
section	O
does	O
.	O
</s>
<s>
The	O
sorting	B-Algorithm
should	O
be	O
done	O
in	O
colexicographic	O
order	O
(	O
string	O
read	O
right-to-left	O
)	O
,	O
i.e.	O
</s>
<s>
in	O
Python	B-Language
.	O
</s>
<s>
(	O
The	O
above	O
control	O
codes	O
actually	O
fail	O
to	O
satisfy	O
EOF	B-Language
being	O
the	O
last	O
character	O
;	O
the	O
two	O
codes	O
are	O
actually	O
the	O
first	O
.	O
</s>
<s>
As	O
a	O
lossless	B-Algorithm
compression	I-Algorithm
algorithm	O
the	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
offers	O
the	O
important	O
quality	O
that	O
its	O
encoding	O
is	O
reversible	O
and	O
hence	O
the	O
original	O
data	O
may	O
be	O
recovered	O
from	O
the	O
resulting	O
compression	O
.	O
</s>
<s>
The	O
lossless	B-Algorithm
quality	O
of	O
Burrows	O
algorithm	O
has	O
provided	O
for	O
different	O
algorithms	O
with	O
different	O
purposes	O
in	O
mind	O
.	O
</s>
<s>
To	O
name	O
a	O
few	O
,	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
is	O
used	O
in	O
algorithms	O
for	O
sequence	B-Algorithm
alignment	I-Algorithm
,	O
image	B-General_Concept
compression	I-General_Concept
,	O
data	B-General_Concept
compression	I-General_Concept
,	O
etc	O
.	O
</s>
<s>
The	O
following	O
is	O
a	O
compilation	O
of	O
some	O
uses	O
given	O
to	O
the	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
Transform	I-Algorithm
.	O
</s>
<s>
A	O
number	O
of	O
alignment	O
programs	O
,	O
specialized	O
for	O
this	O
task	O
,	O
were	O
published	O
,	O
which	O
initially	O
relied	O
on	O
hashing	B-Error_Name
(	O
e.g.	O
,	O
Eland	O
,	O
SOAP	O
,	O
or	O
Maq	O
)	O
.	O
</s>
<s>
In	O
an	O
effort	O
to	O
reduce	O
the	O
memory	O
requirement	O
for	O
sequence	B-Algorithm
alignment	I-Algorithm
,	O
several	O
alignment	O
programs	O
were	O
developed	O
(	O
Bowtie	B-Application
,	O
BWA	O
,	O
and	O
SOAP2	O
)	O
that	O
use	O
the	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
.	O
</s>
<s>
The	O
Burrows	O
–	O
Wheeler	O
transformation	O
has	O
proved	O
to	O
be	O
fundamental	O
for	O
image	B-General_Concept
compression	I-General_Concept
applications	O
.	O
</s>
<s>
For	O
example	O
,	O
Showed	O
a	O
compression	O
pipeline	O
based	O
on	O
the	O
application	O
of	O
the	O
Burrows	O
–	O
Wheeler	O
transformation	O
followed	O
by	O
inversion	O
,	O
run-length	B-Algorithm
,	O
and	O
arithmetic	O
encoders	O
.	O
</s>
<s>
The	O
pipeline	O
developed	O
in	O
this	O
case	O
is	O
known	O
as	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
with	O
an	O
inversion	O
encoder	O
(	O
BWIC	O
)	O
.	O
</s>
<s>
The	O
results	O
shown	O
by	O
BWIC	O
are	O
shown	O
to	O
outperform	O
the	O
compression	O
performance	O
of	O
well-known	O
and	O
widely	O
used	O
algorithms	O
like	O
Lossless	B-Algorithm
JPEG	O
and	O
JPEG	O
2000	O
.	O
</s>
<s>
More	O
recently	O
,	O
additional	O
works	O
like	O
that	O
of	O
have	O
shown	O
the	O
implementation	O
of	O
the	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
Transform	I-Algorithm
in	O
conjunction	O
with	O
the	O
known	O
move-to-front	B-Algorithm
transform	I-Algorithm
(	O
MTF	O
)	O
achieve	O
near	O
lossless	B-Algorithm
compression	I-Algorithm
of	O
images	O
.	O
</s>
<s>
BWT	O
has	O
also	O
been	O
proved	O
to	O
be	O
useful	O
on	O
sequence	O
prediction	O
which	O
is	O
a	O
common	O
area	O
of	O
study	O
in	O
machine	O
learning	O
and	O
natural-language	B-Language
processing	I-Language
.	O
</s>
<s>
proposed	O
a	O
sequence	O
prediction	O
scheme	O
called	O
SuBSeq	O
that	O
exploits	O
the	O
lossless	B-Algorithm
compression	I-Algorithm
of	O
data	O
of	O
the	O
Burrows	B-Algorithm
–	I-Algorithm
Wheeler	I-Algorithm
transform	I-Algorithm
.	O
</s>
<s>
SuBSeq	O
exploits	O
BWT	O
by	O
extracting	O
the	O
FM-index	B-Algorithm
and	O
then	O
performing	O
a	O
series	O
of	O
operations	O
called	O
backwardSearch	O
,	O
forwardSearch	O
,	O
neighbourExpansion	O
,	O
and	O
getConsequents	O
in	O
order	O
to	O
search	O
for	O
predictions	O
given	O
a	O
suffix	O
.	O
</s>
