On this page https://en.cppreference.com/w/cpp/container/set/set, it says:
4-5) log(N) where N = std::distance(first, last) in general, linear in N if the range is already sorted by value_comp().
Isnt that incorrect? I would expect it to be O(NlogN) in the general case because you are inserting elements N times into the tree and each insertion takes logN time.
Here's what the standard says about the complexity [set.cons]p4:
Complexity: Linear in N if the range [
first,last) is already sorted with respect tocompand otherwise N log N, where N islast - first.
So it seems like a typo on cppreference, but someone can fix it: https://en.cppreference.com/mwiki/index.php?title=Template:cpp/container/constructor_ord§ion=2&action=edit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With