https://ide.codingblocks.com/s/243007 here is the code bhaiya explained in the video. In line 20 why do we specify arr[s]<=key? This shouldn’t be necessary? Since this condition won’t be violated ever? Please give a case where this particular condition gets violated or holds significance.
Rotate Array Binary Search
hello @rachitbansal2500
consider this case.
4 5 8 2 3
if mid is on 8 and key = 2 ,then going to left will give wrong answer.
this is because in left we have elements raning from 4 to 8 and clearly 2 is not present in them.
thats whys adding this a[s] <= key to make sure that we are going in right direction
Hey this case wouldn’t be considered since we are rotating the array through the middle and therefore a sorted array that is:
2 3 4 5 8
when rotated will result in:
5 8 2 3 4
no bro, array can be rotated from any position .
pls check question once again
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.