How to calculate O(Log(N))?
algorithm, arrays, complexity-theory
Solution
You have misunderstood the concepts of algorithmic order of growth. Please read a book on algorithms and get your concepts strong. In any case I'll try explaining at a high level,
If you have an array of 10 elements like you said, and you do a "normal search" (It's called Linear Search) you are iterating through each element in the array, which means that if there are 'n' elements 'n' elements have to be checked. So it's O(n) not O(10). If it were O(10) [ btw, O(10) = O(1) ] that would mean that the it would always take 10 iterations or less, no matter how many elements there were in the array, which is not the case. If your array had 100 elements, it would take 100 iterations so we say the order is O(n) where n is the input size (here the size of the array).
The above method is for a non sorted array, for a sorted array we can use a faster method to search, much like how you would look up a word in a dictionary, this technique is called Binary Search. What happens here is, you look up the middle element of the array and see where the number you are searching for lies, either on the first half or the next half. Then, you select the half you want and apply the same method of dividing into half and checking. Since this is being done recursively, it uses logarithmic growth (in case of binary search, it is log to base 2). Please read up on Binary Search and logarithmic order of growth for a better understanding.
Problem
I want to know exactly how to calculate O(Log(N)) for this exemple : we have a sorted array of 10 elements [1 3 4 8 10 15 18 20 25 30] When we do a normal search we have a complexity of O(10) that means that we have to check every case of the array so O(10) = 10. but if we do a dichotomic search because we have a sorted array we have a complexity of (O(Log(10)) what's is the result of this notation O(Log(10))= ??? ? i have a missunderstand shall we use Log base 10 or 2 or what exactly ? thanks for the help