Move To Front Encoding and Decoding
Move To Front Encoding and Decoding
Move-To-Front Encoding
Prepared By:
Dr. Swati Singh
Assistant Professor, CSE Deptt
IMS Engineering College, Ghaziabad
DR. A. P. J. ABDUL KALAM TECHNICAL UNIVERSITY, Uttar
Pradesh
Need of Move-To-Front Encoding
Move-to-Front encoding, takes input as string and gives output as a s
numbers, one for each character in the input string.
If the input string has lots of sequences containing the same letter in a
then the output series will have a lot of small values.
This means: If we have an input string with lots of sequences containi
same letter in a row, then we can first apply Move-to-Front encoding.
This gives us a new series which contains lots of small numbers.
Then we can apply any encoding, in which we choose to use less spac
small numbers than on bigger numbers.
The end result should then be a shorter sequence than the original one
Move-To-Front Encoding
The MTF (Move to Front) is a data transformation algorithm that
restructures data in such a way that the transformed message is
more compressible.
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.
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.
Move-To-Front Encoding
A Move-To-Front coder is used for preprocessing the input
before it is fed to the actual compressor.
Encoding works as follows:
The coder maintains a list L containing all the 256 characters
that can appear in the input.
Whenever it receives an input character c it looks up the
position i of c in L , outputs i and moves c to the front of L .
Let us look at an example.
Assume that the position of every character in the initial
list is equal to its ASCII-code.
When we encode the sequence aaabbbbaab
we obtain the output 97, 0, 0, 98, 0, 0, 0, 1, 0, 1 .
Move-To-Front Encoding
A MTF Coder has the following properties:
If the input contains sequences where one character is repeated many tim
then the output will have a lot of consecutive zeros.
0 1 2 3 4
a b c d e
Move-To-Front Encoding
First input character: "c"
L= "ccdcabb“
The list is:
0 1 2 3 4
a b c d e
c a b d e
Move-To-Front Encoding
Next input character: "c" (the second c in "ccdcabb")
The list is:
d c a b e
Move-To-Front Encoding
Next input character: "c"
L=
"ccdcabb“
This will output “1", since c is at position 1, and now we will
move c to the front, pushing d to the right.
c d a b e
Move-To-Front Encoding
Next input character: “a"
L= "ccdcabb“
This will output “2", since a is at position 2, and now
we will move a to the front, pushing c, d to the right.
0 1 2 3 4
a c d b e
Next input character: “b“
This will output “3", since b is at position 3, and now we will
move b to the front, pushing a,c, d to the right.
0 1 2 3 4
b a c d e
Prepared By:
Dr. Swati Singh
Assistant Professor, CSE Deptt
IMS Engineering College, Ghaziabad
DR. A. P. J. ABDUL KALAM TECHNICAL UNIVERSITY, Uttar
Pradesh
Move-To-Front Algorithm
The MTF (Move to Front) is a data transformation algorithm that
restructures data in such a way that the transformed message is
more compressible.
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.
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.
Move-To-Front Algorithm
A MTF has the following properties:
If the input contains sequences where one character is repeated many tim
then the output will have a lot of consecutive zeros.
So, this consecutive zeros signifies the same symbol occurrence in decod
Move-To-Front Decoding
The output of MTF encoder is a position in the list and not an actual
or character, and then it proceeds to transform the table.
Thus, because the table is transformed only after the position is transm
the MTF decoding algorithm also maintain the same table created by
encoding method, since they both start with the same list.
The decoder accepts list positions and not symbol codes.
In Decoding we have “translate” that list position into the correct out
symbol found at that list position.
Again, the table would have to be reconstructed to move-to-front the n
symbol received.
Hence, the same table is being used as a “look-up” table of the MTF
encoding and decoding algorithms for reconstruction of the data sourc
Move-To-Front Decoding
Use Move-To-Front Decoding Scheme to decode “2031233“,
assume the source alphabet is given by A={a b c d e}.
Solution:
We start by creating a list(L) of all possible characters that may occur in an input
stream.
0 1 2 3 4
a b c d e
Move-To-Front Decoding
First list position: “2"
decode “2031233“
The list is:
0 1 2 3 4
a b c d e
c a b d e
Move-To-Front Decoding
Next list position : “0“ decode “2031233“
The list is:
d c a b e
Move-To-Front Decoding
Next list position : “1"
decode
“2031233
This “ “c", since c is at position 1, and now we will
will output
move c to the front, pushing d to the right.
c d a b e
Move-To-Front Decoding
Next list position : “2"
decode “2031233“
This will output “a", since a is at position 2, and now
we will move a to the front, pushing c, d to the right.
0 1 2 3 4
a c d b e
Next list position : “3“
This will output “b", since b is at position 3, and now we will
move b to the front, pushing a,c, d to the right.
0 1 2 3 4
b a c d e