Quote Originally Posted by mickey View Post
what I don't still understand is:
Qt Code:
  1. search (45); -> this is what'll happen in the worst case. And it's O(n).......and array was sorted.....It isn't O(logN)
To copy to clipboard, switch view to plain text mode 
Yes, great analysis!
It is O(n) because you searched in an array, not in a balanced binary tree and because you used the wrong searching algorithm.
To get the time you want you have to use a O(logn) sort algorithm such as qsort to sort the array and then use binary search to find a value.