let us say I’m looping through a vector and incrementing the count whenever a number is encountered, I’m using an ordered map for the purpose,
my question is what is the total TC of the loop is it O(n) or O(nlogn).
The time complexity is O(NLog(N)) this is because when you are using map they are implemented in the form of trees hence each insertion takes log(N) time thus total it takes O(N* Log(N)) time.
The time complexity would have O(N) if you would have use unordered_map<> because they are implemented internally using hashing.
If you want to know more I think you can find interesting articles.
Hope this answers your query.
Hey I have answerered in depth in this article:
Please refer this forum if you are interested