HI,
I dont know whether you are aware of binarySearch algorithm.
Let me explain:
if you have the array a1 with following elements:
gopi giri geethika gani
And say you are searching for "gani".
The size of the array is 4 here. first it will calucalte mid = (low+high)/2
Here it will be 1 { (0+3)/2 }. Then it will for check a1[mid] which is "giri".
And compares with "gani". As per
string comparison, "gani" will come before "giri" so it tries to search the first half of the array and ends in no match found. "gani" cab be inserted at index 0 to keep the array sorted so the method will return -1 (-0-1) as result!
If we are searching for "gopi", as "gopi" will come after "giri" (alphabetical order), it will search the second half of the array and ends in no match found. And the result will be -5 (-4-1).
Hope you will get it!