Is there a easy way to search in an array like this? Some examples below :
5 6 7 8 19 45 21 32 40 // Rolled over at 7 th element
15 22 32 45 121 341 40 // Rolled over at 7 th element
1 22 32 45 121 341 400 // Rolled over at 0 th element
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.
Any algorithm to find “rollover” point would have at least O(n) complexity in worst case.
Imagine, you have sorted array and checked less than n of its elements. For example, if in array
1 2 3 4 5 6 7 8 9 10you didn’t check element4, I can replace it with100and create “rollover” (1 2 3 100 5 6 7 8 9 10). Your algorithm won’t know, since it never read this element.Thus, your only option is to go through all elements until you find rollover.
Thanks to Eyal Schneider for a useful comment.
BTW, am I the only one here who doesn’t understand etymology of the word “rollover”?