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.
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 ratings0% 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.
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))