Can anyone give me an answer to this?  
Author Message
pmanisekaran





PostPosted: Visual C# Language, Can anyone give me an answer to this? Top

Your program will be fed 800 distinct numbers from of a range of 8001 to 9000. You need to store these in-memory and then print. How would you do it Thinking of an array of ints Well, that would need around (4 x 800 = 3200) bytes. Can you reduce the required memory further (by more than 20 times)

Regards

Mani




Visual C#19  
 
 
anomolous





PostPosted: Visual C# Language, Can anyone give me an answer to this? Top

What if you only had to store 1 bit to indicate if a number was in the list or not in the list How many bits would you need What would be the memory requirements
 
 
RizwanSharp





PostPosted: Visual C# Language, Can anyone give me an answer to this? Top

short can save any number in the range you specified! So using short instead of int saves you 50% of the memory 800 X 2 = 1600 bytes!

Best Regards,



 
 
Matthew Watson





PostPosted: Visual C# Language, Can anyone give me an answer to this? Top

This is a coursework question, I bet.

Anomolous has already given the answer. You use one bit for each number between 8001 and 9000, which will take a total of 1000 bits.

The method that stores 32-bit ints would take 32*800 = 25600 bits.

Therefore the proportional space saving is 25600/1000 = 25.6. (Which is more than 20!)

 
 
pmanisekaran





PostPosted: Visual C# Language, Can anyone give me an answer to this? Top

Thanks for the answer Anomolous

There is a bitarray class which does the job cleanly

By the way, I could also have boolean array if system stores bool as bits. Does bool take one bit

Regards

Mani



 
 
Matthew Watson





PostPosted: Visual C# Language, Can anyone give me an answer to this? Top

No, a bool is a byte (8 bits).