Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def recursive_binary_search(search_space):
- n = len(search_space)
- a, b = search_space[n/2:], search_space[:n/2]
- print(a,b)
- if (sum(a) > sum(b)):
- if n <= 2:
- x, y = search_space[0], search_space[1]
- return x if x > y else y
- else:
- return recursive_binary_search(a)
- elif (sum(b) > sum(a)):
- if n <= 2:
- x, y = search_space[0], search_space[1]
- return x if x > y else y
- else:
- return recursive_binary_search(b)
- else:
- return search_space[round(n/2)]
- random_int_array = [random.randint(0,1000) for x in range(100)]
- print(recursive_binary_search(random_int_array))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement