What is the worst case time complexity of a binary search algorithm?
O(n log n)
Worst case scenario means assuming element is not available in the given sorted array. in this case we have to check all the elements. but since in each iteration we will skip half of the elements so worst case goes to O(log n) times. eg: if array has 32 elements log 32 base 2 is 5. so O(log 32) is equal to 5. so in the worst case also binary search will take 5 comparisons.
Back To Top