binary search middle value calculation

后端 未结 4 1619
野性不改
野性不改 2021-02-01 16:42

The following is the pseudocode I got from a TopCoder tutorial about binary search

binary_search(A, target):
   lo = 1, hi = size(A)
   while lo <= hi:
               


        
4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 17:00

    Yes, (hi + lo) / 2 may overflow. This was an actual bug in Java binary search implementation.

    No, there are no other reasons for this.

提交回复
热议问题