Find next lower item in a sorted list
- by Sebastian
Hey guys,
let's say I have a sorted list of Floats. Now I'd like to get the index of the next lower item of a given value. The usual for-loop aprroach has a complexity of O(n). Since the list is sorted there must be a way to get the index with O(log n).
My O(n) approach:
index=0
for i,value in enumerate(mylist):
if value>compareValue:
index=i-1
Is there a datatype for solving that problem in O(log n)?
best regards
Sebastian