DarkKunai99
DarkKunai99

Reputation: 115

What's the run time of calling the size() function for C++'s containers

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

Answers (1)

Germán Diago
Germán Diago

Reputation: 7663

O(1) if you mean that, for size.

For std::find it is O(n) in the number of elements.

Upvotes: 1

Related Questions