I need help analyzing this programming technique to compress an array

Hopefully readers know the Shannon information theory, which says that the content related to event a with probability p (a) is -log (p (a)). In non-professional conditions, if you need to represent a number in the range from 0 to 7, you will need at least -log (1/8) = log (8) (where base is 2), i.e. 3 bits.

Suppose there is an array of integers from 0 to 255. Instead of storing the array as 8-bit numbers, I first sort the array in ascending order (keeping a backup). Instead of encoding each element of the array as an 8-bit integer, I will output its position in the sorted array. Now the problem is to let the decoder or receiver know this sorted array. I will post the first (smallest) integer value as an 8-bit number, then the increment, which should be added to this number soon. First, the entire sorted array, followed by the order of the elements, i.e. position values.

Example: source array-> 231, 3, 45, 0, 23, 32, 78

sorted array-> 0,3,23,32,45,78,231

the encoded information is 0 (the first element of the sorted array is 8 bits num), then 3 (this increment is more than 0), then 20, then 9, then 13, then 33, then 153.

after sending the first number and consecutive deltas I will send the order, i.e. since there are 7 integers here, I will need a three-bit number for order, 3 (position 0 in the original array), then 1 (position 3), then 4 (position 23), then 5 (position 32), then 2 (position 45) , then 6 (position 78), then 0 (position 231).

Now the position values ​​are now 3, 1, 4, 5, 2, 6, 0

Analyze if this circuit will be compressed:

first number-> 8 bits (in fact, this may require fewer bits, since it is the smallest)

6 β†’ 5 ( , 0,3,20,9,13 5 , 33 153, , , 31 ( 5 ))

7 3 β†’ 21

total- > 8 + 6 * 5 + 21 = 59. , 56 , 7 8 , , , , .

.

0 8- , 231. 3 0, 153 231, 20, 33, 9, 13

.. - > 0,3,20,9,13,33,153, 3,153,20,33,9,13

, , , , 0, 231, 3, 153 , 3, 20, , .. 78, 20 75 ( , (3 + 76 ()) 78, .

, .

0, 3, 23, 32, 45, 78, 231

, 7 , - 32. 32 8 , . .. 32 3, 29 (.. 32-3), 46 (78-32), 0 3 (3-0), 23 20 (23-3), 45 33 (78-45), 231 153 (231-78).

, , .

32 ( 0-255, 8 ), 29 ( 0-32, 6 ), 46 ( 32-255 8 ), 3 ( 0-3 2 ), 20 ( 3-32, 5 ), 33 ( 32-78 6 ), 153 ( 78-255 8 )

8 + 6 + 8 + 2 + 5 + 6 + 8 = 43, , 38 (8 + 5 * 6 ), 7 43 + 21 = 64 56. .

, 21 . , , , 7 , log (7) + log (6) + log (5).... log ( (7)), 2.

, log (a) + log (b) = log (ab)

12,299, 43 55,299, 56. . 3 ( 7) +3 ( 6) +3 ( 5) +2 ( 4) +2 ( 3) +1 ( 2) +0 ( 1) = 14, 43 57, .

1- . 56 55 - , 55 54 . , . , , .

, , 43 43. . , . i.e , , 43.

3,1,4,5,2,6,0 , 5040 0 6. 13 (12,299, ).

, .

+5
2

56 55 - , 55 54 . , . , , .

- - , . . n , 2 ^ n. n-1 , 2 ^ (n-1) . , , , , . , 2 ^ (n-1) , ( ), . , - .

, , , . - , , , k . k , .

.

, , , , . , , [1, 2, 3, 4, 2 ^ 30, 2 ^ 30 + 1, 2 ^ 30 + 2, 2 ^ 30 + 3], . . , . , , , 1 .

. , [2 ^ 30, 2 ^ 30 + 1, 2 ^ 30 + 2, 2 ^ 30 + 3], , , , , . , , ( ) n , n - .

+1

1- .

. , , , .., , , .

2 ^ k , k - . , , k-1- . 2 ^ (k-1) . , 2 ^ (k-1) , , , 2 ^ (k-1) . 2 ^ (k-1) . , , 2 ^ k . .

+1

All Articles