Блог пользователя ghost1733

Автор ghost1733, история, 3 года назад, По-английски

So today I learnt a new thing, which I think will be useful for beginners. I thought that both of the lines are equivalent. However when I found out that the latter is more efficient in case of sets.

set set1;

auto ite = upper_bound(set1.begin(), set1.end(), val); // O(n) // O(log n) in case of random access container. auto ite = set1.upper_bound(val);//O(log n) // binary search, uses set property

Hope this helps; return 0;

  • Проголосовать: нравится
  • -10
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ghost1733 (previous revision, new revision, compare).

»
3 года назад, # |
  Проголосовать: нравится +22 Проголосовать: не нравится

Important rule for beginners: learn how containers are implemented before using them. This will discover differences in find, lower/upper_bound, as well as differences between ordered and unordered set/map. Very important stuff!