My guess is O(n) where n is the no. of bits. Or is it constant w.r.t. n? I mean it shouldn’t it just be able to copy the bits from memory?
The bitset::any() is an inbuilt function in C++ STL which returns True if at least one bit is set in a number. It returns False if all the bits are not set or if the number is zero. Parameter: The function does not accepts any parameter.
As expected, the BitSet with the same number of bits consumes around 1 KB, which is far less than the boolean[]. The above code will compute the object size for both types of bit-vectors with different lengths.
As bitset stores the same information in compressed manner the operation on bitset are faster than that of array and vector.
bitset::set() is a built-in STL in C++ which sets the bit to a given value at a particular index. If no parameter is passed, it sets all bits to 1. If only a single parameter is passed, it sets the bit at that particular index to 1.
Mathematically speaking, long has a fixed length, therefore copying it's contents is constant-time operation. On the other hand, you need to zero-out the rest of the bits in the bitset and that you are not able to do in less-than-linear time with respect to the length of the bit_set. So, In theory you cannot do better than O(n), where n is the length of the bitset.
I guess that from the asymptotical complexity point of view you can safely assume that the complexity of the constructor is the same as zeroing-out the allocated memory.
This analysis however has some value only for huge values of n and it does not make much sense to me to use a long constructor to initialize a bitset of million bits. So, if the size of the bitset is on the same scale as the size of long, it is practically constant-time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With