The ISO C ++ standard defines the complexity of algorithms and methods for accessing containers where necessary. In any other place (unless indicated explicitly), all bets are disabled, and the library developer is free to carry out his own implementation.
For example, you can assume that maps and sets are implemented using red-black trees, but this is not required. Many algorithms are overloaded or specialized for certain categories of iterators (for example, Random Access Iterator), and sometimes they can even be optimized for using special equipment (for example, XMM-register and performing some parallel operations).
Sometimes you really need to logically assume how much the operation may cost due to other requirements, for example, splicing in std :: list should have O (1) complex => length has O (n).
I have a book from N. Josuttis C ++ Standard Library - a textbook and reference book, and all these aspects are well covered there.
Best wishes,
Hovhannes
source share