In the page 159 of the book OCA Java SE 8 there is a question about binary search whose correct answer apparently is "The result is undefined". Although I know that the array should be sorted in order to use binary search properly, and I don't think that knowing the binary search algorithm is part of the exam, I understand that the question is asking about an edge case, because the value which is intended to be searched is exactly in the middle of the array, and therefore, the result would actually be predictable. Is my understanding correct? I am asking because I don't remember seen any related comments in the errata.
sven langrew wrote:. . . Is my understanding correct? . . .
Afraid not. You were right to pick up that link, which is about the very same question. Because the documentation says the results are undefined, “undefined,” is the correct answer. It is only by luck that a binary search can find 12 in that array at all. An alteration to the algorithm, for example starting to search at the midpoint − 1 rather than its midpoint, would produce a completely different result.