---
title: In-Place BWT Algorithm
url: https://www.emergentmind.com/topics/in-place-bwt-algorithm
type: topic
---

# In-Place BWT Algorithm

The in-place Burrows–Wheeler Transform (BWT) algorithm is a class of procedures that compute the BWT of a string by continuously overwriting the input buffer, maintaining only a constant number of auxiliary variables. Starting with Crochemore et al.’s foundational method, recent research has extended the technique to construct additional suffix-related arrays in constant workspace and provided hardware implementations with fixed-cycle throughput. These algorithms have also facilitated direct in-place computation of Lyndon-related structures and bijective variants. Despite quadratic runtime, in-place BWT and its extensions remain central to time/space tradeoffs in suffix processing for both software and hardware applications.

## 1. Algorithmic Foundations and Lexicographic Insertion

The original in-place BWT algorithm of Crochemore et al. operates by incrementally constructing the BWT of progressively longer suffixes $T[s..n-1]$ of the input $T = T_0 T_1 \ldots T_{n-2} \$$. For each index $s$ descending from $n-2$ to $0$, the procedure locates the end-marker \$ in the current suffix buffer, determines the rank $r$ of $T_s$ among all suffixes $T_s, T_{s+1}, \ldots, T_{n-1}$, and performs a controlled cyclic shift to integrate $T[s]$ at the correct lexicographic position.

The rank $r$ is given by:
$$
r = \left|\{i \in [s+1, n-1]: T[i] < c\}\right| + \left|\{i \in [s+1, p]: T[i] = c\}\right|,
$$
where $c = T[s]$ and $p$ is the location of \$ in $T[s+1..n-1]$.

This ensures the BWT is built by a series of local, in-place updates, preserving a lexicographically sorted suffix ordering with only $O(1)$ extra integer variables (indices, counters, loop variables) [2512.20869].

## 2. Pseudocode, Buffer Invariants, and Rank Maintenance

The computational steps for each iteration $s$ are succinctly captured in the following routine:
```plaintext
procedure InPlaceBWT(T[0..n-1]):
  for s from n-2 downto 0 do
    c ← T[s]
    for (p ← s+1; T[p] ≠ '$'; p++) do ;
    r ← 0
    for i from s+1 to n−1 do
      if T[i] < c then r ← r + 1
      else if T[i] == c and i ≤ p then r ← r + 1
    T[p] ← c
    for i from s to s+r-1 do
      T[i] ← T[i+1]
    T[s+r] ← '$'
    // optional: update ISA values stored in T[s..n-1]
  end for
```
After each step, the suffix buffer $T[s..n-1]$ holds the BWT of $T[s..n-1]$. If the inverse suffix array (ISA) computation is enabled, lexicographic ranks are incrementally updated in-place: any rank $q \ge r$ becomes $q+1$, while $T_s$ is assigned $r$ [2512.20869].

## 3. Space/Time Bounds and Extensions to LCP, Lyndon, and Bijective Transforms

In-place BWT runs in $O(n^2)$ time: each of $n$ iterations scans and shifts $O(n)$ elements. No auxiliary arrays or stacks are allocated; only $O(1)$ extra variables are used.

Several extensions have been realized in the same framework:

- **LCP array construction**: By adding two scans per suffix insertion, the longest common prefix (LCP) values are computed and shifted in constant extra space along with the BWT. Elias δ-coding enables further in-place compression of the LCP array [1611.08198].
- **Lyndon array computation**: After building the ISA, the Lyndon array is produced in-place by performing a next-smaller-value (NSV) scan: for each $i$, $LA[i] = \min\{j > i : ISA[j] < ISA[i]\} - i$. This is implemented via a double loop overwriting ISA values, also in $O(n^2)$ time [2512.20869].
- **Bijective BWT and conversions**: The in-place paradigm extends to the bijective BWT (BBWT), leveraging Duval’s Lyndon factorization. Factor-by-factor insertion maintains EBWT order; in-place inversion or conversion between BWT and BBWT is also quadratic in time, using only constant extra workspace [2004.12590].

## 4. Hardware Pipeline Realizations

The in-place BWT algorithm lends itself to hardware accelerators due to its regular update pattern and fixed workspace. In a register-based scanchain architecture, each input block is held in a sequence of flip-flops. On each iteration, the chain is shifted, new character loaded, and the insertion rank computed using parallel comparators. Population counts for “$\le c$” and “$< c$” flags determine the new insertion index; updates are distributed over a fixed pipeline of six clock cycles per character, yielding input-independent, constant-latency execution.

Reported throughputs for FPGAs and ASICs demonstrate practical feasibility:
- **FPGA**: Xilinx VU9P (no BRAM); 66 MB/s for 128-byte blocks at 345 MHz.
- **ASIC**: 65 nm CMOS; 161 MB/s for 128-byte blocks at 843 MHz [2209.01951].

The block buffer contains only the working string, with all updates performed without supplementary RAM or output arrays.

## 5. Correctness, Inductive Invariants, and Suffix Structures

After iteration $s$, $T[s..n-1]$ encodes both $BWT(T_s)$ and, optionally, $ISA(T_s)$. The rank-update lemma $ISA_s(j) = ISA_{s+1}(j) + \mathbb{1}_{ISA_{s+1}(j) \ge r}$ for $j = s+1..n-1$ and $ISA_s(s) = r$ guarantees consistent ordering. For LCP or Lyndon array computation, additional scans respect the sorted neighbor relations through local rank properties and LF-mapping, with $O(1)$ auxiliary variables at each step.

The algorithms retain correctness under unbounded alphabets, as all decisions are based only on local comparisons and position updates, not enumeration or counting across the alphabet $\Sigma$.

## 6. Space-Time Tradeoffs and Compression Techniques

If $k$ words of workspace are permitted, suffixes can be inserted in batches of size $k$, with $O(n^2/k)$ scans per batch, resulting in a total time of $O((n^2/k+n)\log k)$ and space $O(k \sigma_k)$, where $\sigma_k$ is the maximum alphabet size in any $k$-window [1611.08198].

For LCP array compression, Elias δ-coding achieves $O(n\log\log n)$ bits on average, shifting and inserting codewords in-place using word-level memmoves and scan-to-decode operations.

The constant-space in-place paradigm thus establishes the quadratic lower bound for maintaining all suffix-derived structures in the buffer, unless nontrivial sampling or parallel bit-vector techniques are introduced on highly repetitive texts.

## 7. Applications, Extensions, and Limitations

In-place BWT algorithms support a range of theoretical and practical applications:
- Suffix and Lyndon array construction for indexing and pattern matching.
- Compression schemes such as bzip2 (as realized in hardware).
- Conversions between classical and bijective transforms for invertibility and unique factorization.

A plausible implication is that, despite the quadratic time, the conceptual simplicity and generality—applicability to unbounded alphabets and lack of workspace dependency—render the in-place BWT invaluable in constrained-memory environments and as a reference procedure for time-space tradeoff analyses.

The in-place BWT method is not intended for high throughput in large-scale settings but rather as a model demonstrating the feasibility of full suffix/transform computation under the strongest workspace restriction [2512.20869].

---

### Table: In-Place BWT Algorithm Features and Extensions

| Extension            | Description                             | Paper (arXiv id)  |
|----------------------|-----------------------------------------|-------------------|
| Lyndon array         | Next-smaller-value scan from ISA        | 2512.20869        |
| LCP array            | 2 scans per suffix insertion            | 1611.08198        |
| Elias-coded LCP      | In-place δ-encoding during shifts       | 1611.08198        |
| BBWT construction    | Factor-by-factor via Duval algorithm    | 2004.12590        |
| Hardware pipeline    | 6-cycle scanchain, parallel popcount    | 2209.01951        |

All the above extensions preserve the fundamental invariants and operate within constant extra space, illustrating the power of this paradigm across suffix-related array computation and transform variants.

Source: https://www.emergentmind.com/topics/in-place-bwt-algorithm