Encoding
To encode a number ''N'', keep reducing the maximum element of this set (''S''max) from ''N'' and output ''S''max for each such difference, stopping when the number lies in the half closed half open range max).Example
Let ''S'' = [0 1 2 3 4 … 10"> – ''S''max).Example
Let ''S'' = [0 1 2 3 4 … 10 be an 11-element set, and we have to recursively index the value N=49. According to this method, subtract 10 from 49 and iterate until the difference is a number in the 0–10 range. The values are 10 (''N'' = 49 – 10 = 39), 10 (''N'' = 39 – 10 = 29), 10 (''N'' = 29 – 10 = 19), 10 (''N'' = 19 – 10 = 9), 9. The recursively indexed sequence for ''N'' = 49 with set ''S'', is 10, 10, 10, 10, 9.Decoding
Compute the sum of the index values.Example
Decoding the above example involves 10 + 10 + 10 + 10 + 9 = 49.Uses
This technique is most commonly used in run-length encoding systems to encode longer runs than the alphabet sizes permit.References
* Khalid Sayood, Introduction to Data Compression 3rd ed, Morgan Kaufmann. Coding theory Data compression Lossless compression algorithms