I'm having one binary string and have to calculate the number of zeros in that string
i know we can solve it with linear time but i want solution with o(k)
where k is number of zeros in string.
N be the length of String 1<=N<10^6
I'm having one binary string and have to calculate the number of zeros in that string
i know we can solve it with linear time but i want solution with o(k)
where k is number of zeros in string.
N be the length of String 1<=N<10^6
Given a string of N
independent bits, you will have to look at each bit at least once. This gives a time complexity of O(N). There is no way to do it asymptotically faster.
The algorithms given in the mentioned questions assume, that the whole bit string fits into a word and can be handled in O(1). This does not hold, if the string can be arbitrarily long.
You can use Hamming weight algorithm, actually calculate hamming distance of the string then subtract
from the size of your binary string (N)