Chapter 10 · Simulation

String Transformation: Burrows–Wheeler Transform

← Chapter 10
1. Generate Rotations
2. Sort Rotations
3. Read Last Column

Rotation Table

BWT Result

–

Not built yet.

Step

Ready.

Burrows–Wheeler Transform

All circular rotations are generated, sorted lexicographically, and the last column is read off to obtain the BWT.

How to use

  • Type a string of up to 12 characters and press Load Input (use Reset to start over with the same input).
  • Add $ appends the $ end marker, which sorts before every letter and digit. The transform is also computed without the marker, but the original string can then be recovered only if the row index is stored as well.
  • Step performs one step: first one rotation per step, then sorting, then reading the last column. Auto Play plays the remaining steps (press again to pause).
  • In the table, the first column (F) is shown in the link color and the last column (L) in red; the newest rotation is highlighted. After sorting, the framed row is the original string; Shift is the rotation amount (with $, this column is the suffix array).

Why is it useful?

Sorting the rotations gathers the characters that precede similar contexts, so the last column contains long runs of equal characters (for example BANANA$ → ANNB$AA). Run-length encoding (RLE) and move-to-front coding compress this well; this is the core of bzip2.

Inverting the transform

The first column F is the sorted version of the last column L. The LF mapping links the i-th occurrence of a character in L to its i-th occurrence in F; the original string is then rebuilt backwards, starting from the row that holds it.

Complexity

This brute-force method builds and sorts n rotations of length n: O(n² log n) time and O(n²) memory. Practical implementations derive the BWT from a suffix array in O(n) or O(n log n) time.