Good article, but there are few miss understanding there.

First, you are mixing things, binary_search is just binary_search, you are adding a sort function inside of it. You are mixing responsibilities.

Binary search expects a sorted array, it’s not responsible to sorte the array.

About the sort: The quick sort algorithm is O(n log n). if python is using it by default which is already greater then O(n).

Second, what you describe is the behavior of a O(logN) and O(N) if you put it in the graph you will see. If your N is small you might have better perfomance with O(N).

Third Thing: BigO is to check the behavior when exposed to large scale. In small scenarios, the inner CPU instructions also counts (comparisons, if, etc)

Rodrigo Farias Rezino
Rodrigo Farias Rezino

Written by Rodrigo Farias Rezino

Writing code for more than 20 years and still learning every day.

Responses (1)