binary search (l+r)/2 or (l+r+1)/2 , not a random choice?

Revision en2, by 2020, 2020-04-11 22:15:39

binary search (l+r)/2 or (l+r+1)/2 i saw this on a topcoder article that one or the other will no give while loop but on some test cases both might not as can be seen in submission 76258234 is where i changed (r+l)/2 to r+l+1/2 from this submission 76258059 and my solution passed so how to decide which one will never give a while loop right now i just do it randomly one and if that doesnt pass i do other

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English 2020 2020-04-11 22:15:39 1 Tiny change: ':76258234]is where ' -> ':76258234] is where '
en1 English 2020 2020-04-11 22:14:18 492 Initial revision (published)