Binary search Algorithm doubt.

Правка en1, от 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 .

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский a_journey 2019-03-16 19:38:21 504 Initial revision (published)