-
Notifications
You must be signed in to change notification settings - Fork 0
Description
The formula is not right, n/k*(n+k)/2->O(n^2) the cost per operation(Amortized complexity) should be O(n).
From More Exceptional C++
Fixed-increment growth. The new buffer should be a fixed amount larger than the current buffer.
For example, a 64-byte increment size would mean that all string buffers would be an integer
multiple of 64 bytes long.
Advantage: little wasted space. The amount of unused space in the buffer is bounded by
the increment size, and does not vary with the length of the string.
Disadvantage: moderate performance. This strategy requires both O(N) allocations and an
average of O(N) copy operations per char. That is, both the number of allocations and the
average number of times a given char is copied vary linearly with the length of the string.
However, control of the constant factor is in the hands of the String implementer