İkili arama algoritması, sıralı bir dizide istenen değeri bulmaya yarayan algoritmadır.

  • En kötü durum performansı: O(log n)
  • En iyi durum performansı: O(1)

Sözde kodEdit

 min = 1;
 max = N; #array size: var A : array [1..N] of integer
 while((A[mid] = x) or (min > max))
    mid := (min+max) div 2;
    if x > A[mid] then
      min := mid + 1;
      max := mid - 1;
   binary_search(Array[0..N-1], value, low, high):
       if (high < low):
           return -1 // not found
       mid = (low + high) / 2
       if (A[mid] > value):
           return binary_search(A, value, low, mid-1)
       else if (A[mid] < value):
           return binary_search(A, value, mid+1, high)
           return mid // found

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on FANDOM

Random Wiki