+ 1

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? https://code.sololearn.com/cQ72snlu9loa/?ref=app

28th Sep 2018, 5:50 PM
Jhon
Jhon - avatar
1 Answer