Match not found "A" "C" "E" "F" "G" "H"
Insert element
at index -1 -2 -3 -4 -5 -6
Array elements "B" "D" "F" "H" "J"
Match found 0 1 2 3 4
Consider that an array has the strings "B","D","F","H","J", . If match is found he binarySearch method returns the index of match. So it can return values from 0 to 4 if match is found
If match is not found it will return the index where the element could have been inserted
Eg:"A" is not in the array but the correct index where "A" can be inserted is 0. Since 0 is already valid it will return -1.
Similarly for "C" it would return -2 since "C" should go between B and D(0 and 1 index)
"K" would be inserted after "J" and hence -6(See above).
Basically we can insert an element that is not found either at the begining of array or end of the array or inbetween the array elements.