This is the worst case scenario for an unbalanced tree - in the above mentioned case your tree becomes a list. On average the complexity is O(logn) and balancing the tree (see AVL Trees) guarantees O(logn) lookup in the worst case too (the insertion is slower though).
Yes, a vector is also an array.2. If I can obtain a search in OLogn(n) with an sorted array, for clearly, I prefer this....I guess it'll be the same of a sorted vector<int>






Reply With Quote
Bookmarks