I know about this question, but mine is a bit different.
Why does rehash
have quadratic complexity, but operator []
(which can call rehash
) has linear complexity in worst case?
Sorry, but I don't have 10 points for adding images, so if by the time you look at this question everything was already fixed, here is what I saw at cppreference:
rehash
complexity:
Average case linear in the size of the container, worst case quadratic.
operator[]
complexity:
Average case: constant, worst case: linear in size.
I know why rehash can have quadratic complexity. However, it is not difficult to make it linear. Therefore, either statement can be true, but not both together (only if different sizes are meant, but then I don't understand what can be taken as a size, except for the number of elements).