For C++ STL containers such as vector
and list
, the complexity of finding elements and inserting or removing them is self-explanatory. However, for the
The elements of a map or set are contained in a tree structure; every time you examine a node of the tree, you determine if the element you're trying to find/insert is less than or greater than the node. The number of times you need to do this (for a properly balanced tree) is log2(N) because each comparison throws out half of the possibilities.
As slavik262 points, maps are usually implemented with red-black-trees, which are self-balanced. Check the complexity of a red-black-tree for example in the wikipedia I don't know any implementation of a map with a binary tree; if Mark Ransom knows one, I'd be pleased to know which one.