Slide 1

Slide 1 text

In-Place BW Transform Chapter 96 in 125 problems book. Speaker: @kgoto Book Reading Seminar #15, January 14, 2022 1 1

Slide 2

Slide 2 text

We call BW-string of We call BW-character of is 0-indexed BW Transform The Burrows-Wheeler transform of length- string is the word composed of the last letters of the sorted conjugates of . BW(x) n x x BW(x) x x[(n + i − 1) mod n] x[i..] x Today's topic Compute BW-string of in time in-place. x O(n ) 2 2 2

Slide 3

Slide 3 text

Strategy Let , and transform to For to (loop-invariant) at the beginning, Transform to in time in-place z = x z = x z = BW(x) i = n − 1 0 z = z ​ = i+1 x[0..i]BW(x[i + 1..n − 1]) z = z ​ i+1 z ​ i O(n) 3 3

Slide 4

Slide 4 text

Observation is a permutation of For , BW-character of on is one of on BW-character of is BW(x[i..]) x[i..] j > i x[j..] x[i..] x[j..] x x[i..] # 4 4

Slide 5

Slide 5 text

Transform to Let be the position of in swap and compute the position ( ) that will be inserted cyclic shift to the left by one z = z ​ i+1 z = z ​ i p # z z[i] z[p] i + r # z[i..i + r] The remain task is to find the rank of . x ​ i 5 5

Slide 6

Slide 6 text

Finding rank of from one of is the common procedure of the backward search on BW-string. be the number of characters smaller than in It is the starting position of suffixes starting with in the suffix array be the numberof characters in It is the position of of suffixes starting with in the suffix array Here, is the rank of of suffixes for . x[i..] x[i + 1..] q x[i] x[i + 1..n − 1] x[i] t x[i] x[i + 1..p − 1] x[i..] x[i] r = q + t x ​ i x ​ j j ≥ i 6 6

Slide 7

Slide 7 text

Compute form ( =bananna) ( =baannaa) ( =baanna#) z ​ i z ​ i+1 z[p] ← x[i] z z[i..i + r − 1] ← z[i + 1..i + r] z z[i + r] ← # z 7 7

Slide 8

Slide 8 text

Time and Space Complexities For each step, the alrotihm runs linear time and in-place. In total, the algorithm runs in time in-place O(n ) 2 8 8

Slide 9

Slide 9 text

Reference The problem is discussed in the following paper. M. Crochemore, R. Grossi, J. Kärkkäinen and G. M. Landau. Computing the Burrows-Wheeler transform in place and in small space. J. Discrete Algorithms, 32:44–52, 2015. 9 9