I just have a simple question, why is the big O notation of a sorted array O(log N)? It will be a sorted array.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Big O notation generally makes sense in context of an algorithm. What operation are you considering when you say the Big O notation is O(log n).
If you mean searching, then it is O(log n) because you can use binary search. Which essentially means you look at the middle element of you array, and if it is greater than the element you’re searching for, you then search the larger half (in the same way), and vice versa (assuming you haven’t yet found your element of course). You can read a more detailed description on wikipedia.
At each step of searching (looking the middle element), you are cutting the size of the array you must search in half since you can now know which side of the middle element your search element must lie. Of course this only works with sorted arrays. For non-sorted arrays, the only search algorithm you can use is linear search where you examine every element in the array which will take on average n/2 inspections.
In general, Big O describes the runtime characteristics of algorithms, so you can’t just ask, what is the Big O of a sorted array, it must be some operation on the array. However, you can consider Big O in terms of the space (memory) taken by some data structure. In this case a sorted array still takes O(n) space to store N elements.