didDid you try to execute the algorithm with an array that has only 1 element.
E (e.g. A=[1].
If A=[1]
)? If you search for the value 1, it'll give "false"false
, or in this case "-1"-1
, because low == highlow == high
and the loop body is never entered despite the value 1 being part of the array. It might be faster, but will fail to deliver the right answer for at least one casescase.