I'm reading Cracking the Coding Interview, and there's the question, "Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?"
Assuming ASCII strings, an obvious solution is to store whether a character has been used before in an array of 256 booleans. A more space efficient solution is to instead use a bit vector. My understanding is that would be implemented something like this: an array of integers, where each bit of an integer is either a true or false value. So, let's say we have 32 bit integers. Then we need an array of 8 such integers to get 32*8 = 256 booleans stored in bits. These will be stored in only 256 bits. On the other hand, if a boolean is stored in n bits, we will need n * 256 bits to store the array.
Here's where I'm confused. The book says that using a bit vector decreases space by a factor of 8. This would only be true if n=8, but I don't think booleans are stored in 2 bytes in Java (the language the book uses), so that is not correct. So, what am I doing wrong/why does using a bit vector decrease space by a factor of 8?
EDIT: I know that there are 8 bits in a byte, the above was just a dumb mistake. Question is answered by comments, as well as an explanation for my confusion.