Jun-04-2020, 03:53 PM
Hi guys,
I'm trying to create a function that searches a key in an unsorted list with a divide-and-conquer algorithm.
Right now it only searches on the right side of the list. How do I manage that it continues searching on the left side of the list?
I'm trying to create a function that searches a key in an unsorted list with a divide-and-conquer algorithm.
Right now it only searches on the right side of the list. How do I manage that it continues searching on the left side of the list?
def divcon(List, begin, end, key): if end > len(List) - 1 or begin > len(List) - 1 or end < 0 or begin < 0: return False m = (begin + end) // 2 if (L[m] == key): return True if begin > end: return divcon(List, begin, m – 1, key) else: return divcon(List, m + 1, end, key)I'd be very grateful for any help.