in this problem we need a reverse sorted array but the input is unsorted please tell me what to do
The input are not reverse sorted
You will not be given a reverse sorted array, but a rotated array. You have to write an algorithm to search an element in that rotated array efficiently. For example : If the sorted array is 1 2 3 4 5, given rotated array is 4 5 1 2 3. This array has been rotated by 2 elements.
thanks for your reply…can you please explain what does “This array has been rotated by 2 elements” means?
Okay so the given array is 1 2 3 4 5. Now 1 rotation would mean that I take the last element of the array and put it in the beginning of the array. So the array becomes 5 1 2 3 4, i.e rotated by 1 element. Similarly, I can take ‘n’ number of elements from the end of the array and place them in the beginning, and that would make the array rotated by ‘n’ elements.