Binary search Algorithm doubt.

Revision en1, by a_journey, 2019-03-16 19:38:21

when we do while(low < high )

suppose i get answer at mid =( low + high ) / 2 ;

if i again set low to mid , then there is a possibility that it will go in infinite loop .

for example :

low = 4 , high = 5 mid = 4

now suppose if mid is true and we again set low = mid , then low will be again 4 and it will go into infinite loop . what to do in that case , should we set low = mid + 1 .

how to decide when to set low = mid and when low = mid + 1 .

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English a_journey 2019-03-16 19:38:21 504 Initial revision (published)