What is the MTF transform?
The MTF (Move to Front) is a data transformation algorithm that restructures data in such a way that the transformed message is more compressible and therefore used as an extra step in compression. Technically, it is an invertible transform of a sequence of input characters to an array of output numbers.
1. In many cases, the output array gives frequently repeated characters’ lower indexes which is useful in data compression algorithms.
2. It is first of the three steps to be performed in succession while implementing Burrows – Wheeler Data Compression algorithm that forms the basis of the Unix compression utility bzip2.
The main idea behind MTF:
1. The primary idea behind MTF is to maintain an ordered list of legal symbols (a to z, in our example).
2. Read one character at a time from input string .
3. Print out the position at which that character appears in the list.
4. Move that character to front of the list and repeat the process until indexes for all input characters are obtained.
Illustration for "panama". List initially contains English alphabets in order. We one by one characters of input to front. input_str chars output_arr list p 15 abcdefghijklmnopqrstuvwxyz a 15 1 pabcdefghijklmnoqrstuvwxyz n 15 1 14 apbcdefghijklmnoqrstuvwxyz a 15 1 14 1 napbcdefghijklmoqrstuvwxyz m 15 1 14 1 14 anpbcdefghijklmoqrstuvwxyz a 15 1 14 1 14 manpbcdefghijkloqrstuvwxyz
1. If the letters occur many times in the input, then many of the output values will be small integers such as 0, 1, 2 etc.
2. Thus, encoding extremely high frequency of these letters makes an ideal scenario for Huffman Coding.
Input : panama Output : 15 1 14 1 14 1 Input : geeksforgeeks Output : 6 5 0 10 18 8 15 18 6 6 0 6 6
Following is the code for idea explained above:
Input text: panama Move to Front Transform: 15 1 14 1 14 1
Time Complexity: O(n^2)
Exercise: Implement Inverse of Move to Front Transform.
- Inverting the Move to Front Transform
- Burrows - Wheeler Data Transform Algorithm
- Move spaces to front of string in single traversal
- Python code to move spaces to front of string in single traversal
- Shannon-Fano Algorithm for Data Compression
- Transform the string
- Check if it is possible to transform one string to another
- Inverting the Burrows - Wheeler Transform
- Transform a string such that it has abcd..z as a subsequence
- Transform One String to Another using Minimum Number of Given Operation
- Minimum characters to be added at front to make string palindrome
- Karatsuba algorithm for fast multiplication using Divide and Conquer algorithm
- Difference between Data Scientist, Data Engineer, Data Analyst
- Move all Uppercase char to the end of string
- Move all special char to the end of the String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.