1 / 8
Settings
<<<>>>
To find the cost of binary search in the worst case, we can model the running time as a recurrence and then find the closed-form solution. Each recursive call to binarySearch cuts the size of the array approximately in half, so we can model the worst-case cost as follows, assuming for simplicity that n is a power of two.
T(n)=T(n/2)+1,T(1)=1
T(n)=T(n/2)+1,T(1)=1