samedi 28 mars 2015

Why is string::resize linear in complexity?

The string needs to delete its old memory, then declare a new memory buffer, both of which are O(1) in complexity. The cplusplus.com reference says this is linear in time complexity. Is this because the old string needs to be copied over? What if you start with an empty string?


Basically I want a string declared with a size n buffer, in O(1) time. Is this possible?


Aucun commentaire:

Enregistrer un commentaire