Sorted rotated integer array, search algorithm -


this question has answer here:

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

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -