this is a binary search algorithm for a sapesely sorted dataset.
i’m stuck in line 7, “mid= (first+last)//2”
let me take an example where i’m on line 15 and the condition is met.
then ‘mid’ would be assigned to ‘right’(line 16)
and then it would break out of nested loop(line 17)
then it would go back to line 6 where parent loop begins.
And here the problem is. line 7
3 possible ways.
- line 7 would override line 16
- line 7 would be dismissed.
- I am wrong about something.
i don’t think 1 is right . if it’s right,it would keep resetting mid to (first+last)//2 and turn into infinite loop
which one is right?