0% found this document useful (0 votes)
28 views2 pages

Pseudo Code

This document discusses the time complexity of the binary search algorithm in the worst, best, and average cases. It presents the pseudocode for binary search and analyzes the time complexity to be O(log n), where n is the length of the sorted array. The analysis shows that binary search performs logarithmically many divisions to the array length in each recursive call to narrow down the search space.

Uploaded by

Asim Habib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Pseudo Code

This document discusses the time complexity of the binary search algorithm in the worst, best, and average cases. It presents the pseudocode for binary search and analyzes the time complexity to be O(log n), where n is the length of the sorted array. The analysis shows that binary search performs logarithmically many divisions to the array length in each recursive call to narrow down the search space.

Uploaded by

Asim Habib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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