Backward search 2026-10-20
Backward search finds a query's matching interval in a suffix array by processing the query from right to left. With inclusive one-based interval , prepending changes it to . An empty interval means no match. This works through the occurrence-order property of the last-to-first mapping.[ref]
Burrows-Wheeler transform 2026-10-20
The Burrows-Wheeler transform appends a unique smallest terminator to a string, sorts its cyclic rotations in lexicographic order, and records the last column. It is reversible because the first and last columns contain the same characters and the last-to-first mapping preserves the occurrence order of each character. The resulting letter arrangement supports both compression and backward search.[ref]
Last-to-first mapping 2026-10-20
In a sorted cyclic rotation matrix, the last-to-first mapping sends the th occurrence of a character in the last column to its th occurrence in the first column. For one-based rows, , where counts smaller characters and counts in the first entries of the last column. It moves a rotation's start one character backwards cyclically. Equal characters retain the lexicographic order of their following sequences, which proves the occurrence-order rule.[ref]
Use one-based row numbers, and write and for the first and last columns. The last-to-first mapping matches the th occurrence of a character in to its th occurrence in : equal characters retain the ordering of their following suffixes. This lets us extend an interval of matching suffixes one character to the left without reconstructing the full strings.
Start with the last query character. Rows of contain C, so the interval of suffixes beginning with C is . Within those rows, the A entries of are at rows and . They are respectively the first and second A entries in all of , and therefore map to rows and of . These are exactly the suffixes beginning with AC. Reading their supplied positions gives matches starting at positions 11 and 3, or positions 3 and 11 in increasing genomic order.
The same calculation can be written as backward search. Let count characters strictly smaller than , and let count occurrences of in , with . Prepending changes an inclusive interval to
Here , and , giving .
Build an FM-index: store the Burrows-Wheeler transform, cumulative character counts , and a structure supporting fast rank queries for . Then each step of backward search uses two rank queries instead of rescanning the last column. A wavelet tree or suitably checkpointed counts can supply these queries while keeping memory manageable. The counting cost is proportional to query length times the rank query cost, rather than repeatedly scanning the whole genome.[ref]
To recover genomic positions, store a sampled suffix array and follow the last-to-first mapping to a sampled position, adding the number of steps taken. More samples trade storage for faster position recovery. Index character counts and sample positions, rather than storing the quadratic-size full cyclic rotation matrix.