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

Автор Girus, история, 20 месяцев назад, По-английски

Good evening all,

I am reaching out, as I had some questions about the editorial for ABC 277 problem C. The editorial for ABC 277 C — Ladder Takahashi states that the time complexity for the aforementioned problem is O(N * log (N)).

  1. Where is this logarithmic factor coming from ? Is this from the set and map data structures which take logarithmic time for insertion and search operation ?
  2. Would the time complexity reduce to O(N) on average if we were to use an unordered_map or unordered_set ?
  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

»
20 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

YES and YES.

Personally prefer map/set over unordered_map/unordered_set in any case where logarithmic operation is not the bottleneck. Plus it's shorter to type map/set. Hash collision is another concern but it's not the issue for this problem.