You are on page 1of 2

Time Complexity of binary search algorithm in

worst,best and average case ρ Series

Aliya Sardar
Magic Department, , LATEX Academy

October 31, 2020


Binary-Search(arr)
Require: :Sorted Array
1: start ← arr[0]

2: end ← arr.length − 1

3: while start ≤ end do

4: mid = (start + end)/2


5:

6: if key == arr[mid] then


7: return mid[i];
8: else if key ≥ arr[mid] then
9: start ← mid + 1
10: else
11: end ← mid − 1
12: end if
13: end while
Time Complexity of Binary Search Algorithm
Array length Binary Division length bin div(d)
n 2d 16 24
n 2d 8 23
n 2d 4 22
n 2d 2 21
Number of divisions can be represented as
logn2 = D
so time complexity of binary search algorithm is O(log(n))

You might also like