Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

STL performance O(ln(n)) questions

Please, can someone explaine this:

If documentations says that STL std::vector finding element speed performace = O(ln(n)), what does it mean.

O(ln(n)) - what is "O", where I can read about that?

And where I can read about performace of other STL containers preformance

Thank you very much

like image 683
VextoR Avatar asked Feb 08 '11 15:02

VextoR


1 Answers

Big O notation is a way to measure how an algorithm will scale as the size of the data on which it is working grows.

Finding an element if a vector is usually O(n), it's only O(lg(n)) when the vector is sorted and you use one of the binary search family of algorithms.

The complexity of each algorithm is specified in the standard and also in any reference (such as the above link to std::lower_bound).

BTW, ln is log on base e, but all logarithms are the same complexity so even though a binary search only performs lg (log2) operations it's technically correct to say it's O(ln(n)).

like image 68
Motti Avatar answered Sep 22 '22 22:09

Motti