A function like bisect_left (assuming I read its documentation correctly) does not really exist for lists.
This makes sense - since you don't have random access in O (1) in lists (remember that Haskell lists are linked by lists, while Python uses something more like a vector), you could not get an O (logn) binary search .
In particular, only getting into the middle of the list takes O (n / 2) steps (this is just O (n)) steps, therefore, an algorithm that includes the middle of the list (for example, binary search) should be in Ξ© (n).
In short - binary search does not make sense in lists. If you work a lot, you probably need a different data structure. In particular, see Data.Set , which internally uses binary trees.
source share