Sorted rotated integer array, search algorithm -
this question has answer here:
- searching number in rotated sorted array 20 answers
an integer sorted array rotated left unknown no of times, write efficient algorithm search element.
example: 4 5 6 7 8 9 1 2 3 4
i thinking every time find mid in binary search compare element extreme end element , take decision on half pick repeat process. wrong? or there efficient algo?
your example array contains duplicates. when there duplicates there no efficient algorithm - must o(n) work in worst case.
to prove this, consider arrays of form:
000000000000000010000000 it rotation of sorted array, in worst cast must iterate on every element see 1 is.
Comments
Post a Comment