Constant time change first k elements of an array in C++?
- by Johny 96
Let's suppose I have an array:
bool eleme[1000000] = {false};
and at some point in my code I change some of the first of the n elements of this array to true.
Afterwards I want to be sure that all elements of the array are false. So I do:
for (int i =0; i < n; ++i)
eleme[i] = false;
which costs T(n).
Is there a way to do this in constant time? E.g. something like
make_false(eleme, n);