set<int> s;
s.insert(1);
s.insert(2);
...
s.insert(n);
I wonder how much time it takes for s.find(k)
where k
is a number from 1..n?
I assume it is log(n). Is it correct?
set<int> s;
s.insert(1);
s.insert(2);
...
s.insert(n);
I wonder how much time it takes for s.find(k)
where k
is a number from 1..n?
I assume it is log(n). Is it correct?
O( log N ) to search for an individual element.
§23.1.2 Table 69
expression return note complexity
a.find(k) iterator; returns an iterator pointing to an logarithmic
const_iterator element with the key equivalent to k,
for constant a or a.end() if such an element is not
found
ok never mind. I found it on the internet. it is nlog(n). http://www.cplusplus.com/reference/stl/set/find/
I'm trying to think in practice, when is good to use set? for most of the time, I think vector and map can be able to do the job. Does anybody have any idea?