I'm new to algorithm in programming and got this problem of implementing the binary search for an unsorted list in python. I figured out how to implement the recursive binary search function below but got into some troubles with recursion depth limit. So I'm curios whether there is another way to implement binary search for unsorted list in python or not:
def binary_search_unsorted(unsortedList, target):
if len(unsortedList) == 0:
return False;
else:
start = unsortedList[0];
if start == target:
return True;
else:
if start < target:
return binary_search_unsorted([n for n in unsortedList if n > start], target);
else:
return binary_search_unsorted([n for n in unsortedList if n < start], target);