I am new to the divide and conquer paradigm. I wanted to verify that there's nothing wrong with this implementation of binary search.
I ran it a few times and it does print the correct result, but I also wanted a sanity check and any possible improvements.
def search(array, item):
if len(array) == 1:
if array[0] == item:
return 1
return 0
mid = len(array) // 2
x = array[:mid]
y = array[mid:]
found = []
found.append(search(x, item))
found.append(search(y, item))
for elm in found:
if elm == 1:
return True
return False
print(search([1,2,3,4], 8))
print(search([1,2,3,4], 3))
Also, the running time of this is \$O(n log(n))\$, correct? \$O(log(n))\$ being the recursion and \$O(n)\$ being the loop that checks the result
list.