Boolean Data structure | Sololearn: Learn to code for FREE!


Boolean Data structure

I came up with this idea of storing numbers in a boolean array. Basically, the index represents the number and its value whether it is true or false represents if the number is in the array. This, I think, would ensure constant time when searching for a number, but at the cost of memory space. An example is provided below. In this case, 100 bytes are used for storing 10 random numbers from 0 to 99. Then, it looks for a number and prints if it was found or not. What do you think about this? do you think it would be usefuel in some applications where time is crucial? I also was wondering if this is similar to hash tables?

9/28/2018 5:50:48 PM


1 Answer

New Answer