Advanced
Burrows-Wheeler Transform
Rearranging strings for better compression.
Time Complexity
O(N)
Space Complexity
O(N)
Interactive Visualization
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
- 1Generating all cyclic rotations of the input string.
- 2Sorting the rotations lexicographically in a matrix.
- 3Extracting the last column of the sorted matrix.
- 4Storing 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.