https://ide.codingblocks.com/s/164077
plz check the code and revert ,thnku
Pivot of sorted and rotated array
Hi @akb.tech17
You have to take n and all n elements of array as input from user then use modified binary search to find pivot element :
- If array[0] <= array[length of array - 1], it means the array is not rotated, so return 0.
- Initialize start = 0, end = length of array - 1.
- Repeat following steps till start <= end
a). Set mid = (start+end)/2.
b). If mid+1 is pivot, then break.
c). If array[start] <= array[mid], it means from start to mid, all elements are in sorted order.
Set start = mid+1, so that we look for pivot in second half of the array.
d). Else set end = mid-1, to look for pivot in first half.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.