Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is find_if on a set linear?

I've ran into a case where set::find is not the correct way to find the object because I'm finding the object in a different way (by std::find_if) than it is ordered in the set. I have not found any complexity information on finding elements this way. I assume it's linear because iterating through a "unordered" container to find a match is linear.

like image 407
James Nguyen Avatar asked Feb 06 '23 17:02

James Nguyen


1 Answers

You can look here and see that the complexity of find_if is linear.

It is because find_if is a generalized algorithm and it doesn't know a certain type of container it works with. So it can't use peculiarities of different containers to boost a search process and just checks all the elements to find the appropriate one.

like image 119
Edgar Rokjān Avatar answered Feb 08 '23 05:02

Edgar Rokjān