Help in Binary Search

Revision en1, by pop3, 2020-12-14 21:33:04

Suppose for a function f(x) , for different values of x , f(x) is a bool value yes(y) or no(n) as:-

$$$nnnnnyyyyynnnnn$$$

Also suppose the check function in bsearch returns (-1) if its in the left 'n' block , (0) if its a 'y', and (1) if its in the right 'n' block.

So I need to find the largest value of x for which f(x) is yes(y). Is it doable by binary search?

(Usually we have f(x) varying as $$$yyyyyynnnnnn$$$ or $$$nnnnnnyyyyyy$$$ and in that we can easily use bsearch.)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English pop3 2020-12-14 21:33:04 498 Initial revision (published)