Basically the time complexity of Binary Search is O(log N). What if all the elements are same. In the bottleneck step. Assuming all the values in the array are the same, we get the following relation :
T(N) = 2 * T(N/2) + constant = 4 * T(N/4) + constant ( 2 * constant = another constant ) = 8 * T(N/8) + constant … = N * T(N/N) + constant = N + constant = O(N)
In that case the time complexity of Binary search will be O(N).
2.1m questions
2.1m answers
60 comments
57.0k users