How to find the time complexity?

What is time complexity for find method in a set in C++?

  • I am inserting N strings each of length K. Had it been integers, the complexity would be log(N). But here we are storing strings, each of size K. What will be the complexity to find a string in this scenario?

  • Answer:

    The complexity of std::set::find() being [math]O(log(n))[/math] simply means that there will be of the order of [math]log(n)[/math] comparisons of objects stored in the set. The actual complexity, therefore, would be [math]O(log(n) * k)[/math], since each comparison can be taken to be of the complexity [math]O(k)[/math].

Anmol Singh Jaggi at Quora Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.