Burrows-Wheeler Transform

medium · compression, transform, bwt

Burrows-Wheeler Transform

Implement the forward and inverse BWT.

Functions

func BWTForward(data []byte) ([]byte, int)
func BWTInverse(last []byte, primary int) []byte

Behavior

  • BWTForward returns the last column and the primary index (row of the original string in the sorted rotations).
  • BWTInverse reconstructs the original data from last and primary.
  • If data is empty, return []byte{} and primary=0.
  • primary is zero-based.

Constraints

  • len(data) <= 512 (naive O(n^2 log n) rotation sort is acceptable).

Notes

  • Rotations are compared lexicographically as byte sequences.
  • The transform is reversible only with the primary index.
Run tests to see results
No issues detected