Answer the question
In order to leave comments, you need to log in
What are number compression algorithms?
There is an array of numbers in 10 bits (that is, a maximum of 1024 values). To store it, you need 2 bytes * the number of numbers. You can divide these numbers by 4 and be able to store the numbers in a one-byte array. But then the lower values \u200b\u200bare lost - the least significant bits. Is there an algorithm that allows you to keep the "top" and "bottom" bits and compress the "middle" ? For example, the numbers 1000 and 2 become 232 and 2 or something similar. I understand that if there is an entire array at once, then you can analyze the "middle" and throw it away, subtracting an insignificant part from numbers greater than some value. But what if the array has not yet been received and there are only individual numbers, and for all of them you will have to use an algorithm without knowing what the results will be at the end?
Answer the question
In order to leave comments, you need to log in
Can be stored in a bitmap, then exactly 10 bits are required for each number. Every 4 numbers take 5 bytes.
There will be a slight slowdown when writing and reading numbers from such an array (We need to find the offset, read some 2 bytes, discard extra bits)
Perhaps the last byte in the array is not fully used (+6 extra bits), when, as in the current solution, you have extra 6 bits per number.
Is there an algorithm that allows you to keep the "top" and "bottom" bits and compress the "middle" ?The thought is rather chaotically expressed, but let me guess:
- if the numbers do not differ much from each other - store their difference
- if the numbers are repeated many times - put them in a dictionary and store the index
What are conventional compression algorithms good for? Want to reinvent Huffman compression?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question