Constant time change first k elements of an array in C++?
Posted
by
Johny 96
on Stack Overflow
See other posts from Stack Overflow
or by Johny 96
Published on 2012-10-13T02:57:58Z
Indexed on
2012/10/13
3:37 UTC
Read the original article
Hit count: 177
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);
© Stack Overflow or respective owner