Reputation: 115
What is the run-time of performing .size() for C++'s list, vector, and String classes?
I believe the container objects have a built in size member that is changed upon the resizing of the container; returning this data member, the process takes constant time.
Upvotes: 0
Views: 186
Reputation: 7663
O(1) if you mean that, for size.
For std::find
it is O(n) in the number of elements.
Upvotes: 1