Burrows-Wheeler transform I. Coding
Description:
The Burrows-Wheeler transform (BWT) is useful for data compression.The algorithm tends to arrange runs of the same character together. The BWT algorithm is used in bioinformatics and in the bzip3 data compression program.
The algorithm:
1, append '|' at the end of the input text. (It is required to unequivocally reconstruct the string, otherwise you can only cyclicly reconstruct the input.),
2, get all possible cyclic permutations (cyclic rotations) of the text, store them in a transformation table,
3, sort the permutations (the rows) into lexicographic order,
4, take the last column as output. (The returned text should include the '|' character).
Hint: note that Javascript's sort() method puts '|' after any letter of the alphabet.
Example:
Input:
ananas
Append '|' at the end of the string:
ananas|
All cyclic rotations:
ananas|
|ananas
s|anana
as|anan
nas|ana
anas|an
nanas|a
Sorting all rows into lexicographic order then take the last column
ananas|
anas|an
as|anan
nanas|a
nas|ana
s|anana
|ananas
Output: last column
|nnaaas
Please note, that it is a coincidence that the first character of the returned text is '|'. You can't take this for granted.
For further information read https://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform
Similar Kata:
Stats:
Created | Jul 6, 2016 |
Warriors Trained | 206 |
Total Skips | 73 |
Total Code Submissions | 59 |
Total Times Completed | 34 |
JavaScript Completions | 29 |
C# Completions | 7 |
Total Stars | 0 |
% of votes with a positive feedback rating | 79% of 19 |
Total "Very Satisfied" Votes | 14 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 16 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |