Method 1
In fact, with an unknown change, you can still make binary code, but its arbitrary gain.
One method doubles the size of the ie list:
[4,5,6, 1,2,3, 4,5,6, 1,2,3] # basically mylist.extend(mylist)
As you can see, I just doubled the size, but the middle part is still ordered.
Now you can view the list before
list[i-1] > list[i]
This will be the beginning of the binary search, and at the end of the same amount will be the end of your binary list.
start = i end = len(list) -1
Now you can do a binary search
Depending on the average value of the data, it may be lower than O(n)
Method 2
You can resort to the list and do a binary search:
O(nlog(n)) + log(n)
Method 3
Linear search of all elements
O(n)
source share