I am still learning recursion principles and trying to write a function which returns max of all values in an array by recursive calls with lower and upper halves of the array.
I know i would need to find the mid point then split the list in two then recall the function to continue doing until each list is at length 1. I am just confused how to continue from there.
Any help is appreciated.
My function:
def bin_max(L):
'''
Returns max of all values in list L by recursive calls with lower and upper
halves of L. If L is empty, this returns -1e20
Ex. usage: bin_max([ 2, 1, 6, 8, -3, 7 -5, 5]) --> returns: 8
'''
minVal = -1e20
if L == []:
return minVal
if len(L) == 1:
return L[0]
mid = len(L)//2
Left = L[:mid]
Right = L[mid:]
if len(Left)> 1:
bin_max(Left)
if len(Right)> 1:
bin_max(Right)