Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Question about OCA Java SE 8 book, page 159

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good evening.

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.

Thanks in advance for your time.

EDIT. Related question: https://coderanch.com/t/688190/certification/Answer-wrong-page
 
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

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.
 
sven langrew
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you sincerely for your time.

Very nice and well-maintained forum by the way.
 
Campbell Ritchie
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sven langrew wrote:Thank you . . .

That's a pleasure

Very nice . . . forum . . .

Thank you
 
please buy my thing and then I'll have more money:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic