Search code examples
c++11stltime-complexityunordered-set

Time complexity of unordered_set<int> find method


What is the time complexity of find method in unordered_set<int>?

And also is it possible to change the hash functions ?


Solution

  • what is the time complexity of find method in unordered_set?

    ...it's right there in the page you linked:

    Complexity:

    Average case: constant.

    Worst case: linear in container size.


    and also it it possible to change the hash functions?

    Yes. Again, look at the documentation!

    std::unordered_map takes an Hash template parameter. It's a customization point where you can inject your own hashing logic. A custom Hash must satisfy the Hash concept.