Given an unsorted binary array, a
, the only allowed operation is all_zeros(a)
, which returns True
iff all of the array's elements are 0.
The complexity of this all_zeros(a)
is o(len(a)) + large overhead constant
I would like to find all the indices which contain 1s, in the least runs as possible of all_zeros A reasonable sub problem is to assume the number of 1s is "much" (say, x100~x1000) smaller than the number of 0s.
Theoretically, this is simply solved by iterating over the array element-wise, and testing all_zeros([element])
.
In practice, the overhead constant forces us to work in as large batches as possible. We can't assume to know the ratio of 1's in the array, but if some algorithm requires that knowledge, please do share it.
I am looking for a conceptual solution, thus I am not specifying the ratio between the overhead constant and the computation time of all_zeros
.
Please notice I am looking for an average case solution, and not for a worst case solution.
This now requires to define a probability distribution over 1's and 0's, but I am trying to keep this at a high level, and I will not go greatly into the details, while still keeping this answerable.
There may be a best case solution, that always gets the minimum overhead. If there is one, it will be accepted.