W
W
we12020-02-24 12:15:09
Algorithms
we1, 2020-02-24 12:15:09

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

5 answer(s)
W
Wataru, 2020-02-24
@wataru

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.

H
hint000, 2020-02-24
@hint000

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:
So that small numbers do not lose their low bits, and large numbers do not lose their high ones?
If I understand you correctly, then congratulations, you invented floating point numbers .

A
Antonio Solo, 2020-02-24
@solotony

- 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

A
Armenian Radio, 2020-02-24
@gbg

What are conventional compression algorithms good for? Want to reinvent Huffman compression?

A
Adamos, 2020-02-24
@Adamos

Your problem is formulated as a heptagonal triangle problem.
It is better to formulate a more general problem - what kind of numbers, how they need to be processed - and, perhaps, you will be prompted for a more adequate solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question