set<int> s; s.insert(1); s.insert(2); ... s.insert(n);
I wonder how long it takes for s.find(k), where kis the number from 1..n? I assume this is log (n). Is it correct?
s.find(k)
k
O (log N) to search for a single item.
§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
The complexity std::set::find()being O(log(n))simply means that there will be a log(n)comparison order of the objects stored in set.
std::set::find()
O(log(n))
log(n)
set
O(k), O(log(n)∗k). , , (k ), ( ) ( )
O(k)
O(log(n)∗k)
:
.