Jim_Moriarty_'s blog

By Jim_Moriarty_, history, 5 years ago, In English

I wanted to ask which one is better to use because avg. case complexity of set is log(n) while that of unordered_set is o(1) while worst case of set is same but that of unordered set is o(n).

And what are the points that we should take care of while using unordered_set so that we can work with no changes in inbuilt unordered_set?

Any help would be appreciated.

  • Vote: I like it
  • +2
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Unordered_set uses std::hash. You can get more about its cons in this article

»
5 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

I suggest you not to use unordered map/set in CF contest for a problem which has large constraints i.e. >= 1e4, because it have chances of being hacked. Better to use custom hashes for unordered_map/set if using as explained in this blog.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You may choose either one to use while adapting the problem you are solving.