There is an array and the distance between any two consequent elements is one (+1/-1). How will you find an element in it. Can it be done in less than O(n) time
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.
Simply start in first position; now consider the difference bewteen the searched number m
;ifarray[0] == mthen we finished; otherwise we have to jump ofabs(array[0] - m)positions; now just repeat this until the end of the array.However, in the worst case we can’t do better than O(n), just consider this case, we want to find 11: