Skip to content
Advanced

Burrows-Wheeler Transform

Rearranging strings for better compression.

Time Complexity
O(N)
Space Complexity
O(N)

Interactive Visualization

Playback Speed
Execution State
STEP 1 / 3
Lexicographical Rotations
BANANA$
ANANA$B
NANA$BA
ANA$BAN
NA$BANA
A$BANAN
$BANANA
Process Description

Generate all cyclic rotations of the string with $ terminator.

Technical Guide

The Burrows-Wheeler Transform (BWT) doesn't compress data itself but rearranges it to make it highly compressible. It groups similar characters together by performing cyclic rotations and sorting them. When combined with Move-To-Front (MTF) and RLE, it forms the basis of the powerful BZIP2 compression algorithm.

Logical Phases

  • 1
    Generating all cyclic rotations of the input string.
  • 2
    Sorting the rotations lexicographically in a matrix.
  • 3
    Extracting the last column of the sorted matrix.
  • 4
    Storing the index of the original string in the sorted list.

Implementation

matrix.sort().map(row => row.last())

Expert Pitfalls

Forgetting to add a unique terminator ($) to make the transform reversible.