Binary searching in sorted and rotated array

how are we applying binary search in left part i.e. the unsorted part, once we don’t find the element in sorted part.

@Akshay123 you have to call the left part if this condition is FALSE arr[mid] <= key <= arr[e]
this condition will work similarly for all parts, whether they are sorted or not. for eg if the array was
7 8 9 1 2 3 4 5 6 and we were searching for 9,
then s = 0, e = 8, mid = 4
now key = 9 does not lie between 2 and 6,
so e = mid - 1 = 3, s = 0, mid = 1,
again 9 does not lie between 8 and 1, (ie the condition isnt satisfied because 1 < 9)
so we search in the left part again

this is how everytime we encounter an unsorted segment of the array, we will either find the key OR move towards a sorted part to look for the key.

Thanks ishita for clearing my doubt

@Akshay123 please mark your doubt as resolved if you are satisfied

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.