Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
have a large array with a range of integers that are mostly not continuous, eg 1-100,1-1000 etc. All integers are positive. What would be the best algorithm to compress this?

All numbers are unique and different increasing.

Also if you can point me to the vb.net implementation of such algorithm that would be great.
Posted

You can use one of the classes in the System.IO.Compression Namespace[^].
 
Share this answer
 
Comments
CPallini 25-May-14 4:34am    
5. Probably the most practical and efficient solution.
Quote:
have a large array with a range of integers that are mostly not continuous, eg 1-100,1-1000 etc.

This is not clear to me.


Quote:
All numbers are unique and different increasing.

If the numbers belongs to a range (e.g. 1-10000) then you may use just the necessary bits to store them (14 bits are enough for storing 0-16383).
For number increasing monotonically you may store the first number and then the differences between the next and the previous. Storing such differences usually requires fewer bits than storing the whole numbers.
Of course you may also try an available, general compression facility like the one suggested by Richard.
 
Share this answer
 
Comments
Rawan Omer 25-May-14 8:03am    
i search if their is a method or algorithm that responsible for compression array of random integer value :(
If your numbers are increasing, compute the differences, as CPallini said, and observe the histogram of these deltas.

If the deltas are repeating often enough, you can use Huffman encoding on them (most frequent values encoded with fewer bits).

If you compute the "entropy" of the histogram, that can tell you how many bits of information will remain after compression.
 
Share this answer
 
v2
Comments
Member 13420508 13-Feb-18 15:23pm    
what to do when the numbers are monotonically decreasing? Because in that case we may get negative deltas.I need help as I am also working on similar problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900