Question: The binarySearchRec that needs to be edited is: def binarySearchRec(alist,item): if alist == []: return False else: midpoint = len(alist)//2 if alist[midpoint] == item: return
The binarySearchRec that needs to be edited is:
def binarySearchRec(alist,item):
if alist == []:
return False
else:
midpoint = len(alist)//2
if alist[midpoint] == item:
return True
elif item
return binarySearchRec(alist[:midpoint], item)
else:
return binarySearchRec(alist[midpoint+1:], item)
2. In the PowerPoint slides for lecture 15, you will find a function that performs binary search on a Python list using recursion. Modify that binarySearchRec (alist, item) function so that it performs ternary search on a Python list. Your new function should find two midpoints that divide the list into three approximately equal size segments. If the item being searched for is found at either of the midpoints, the function should return True. If the item being searched for is less than the value at the first midpoint, ternary search continues with the segment to the "left" of the first midpoint. If the item being searched for is greater than the value at the second midpoint, ternary search continues with the segment to the "right" of the second midpoint. Otherwise, ternary search continues with the segment between the first and second midpoints. Name your function ternarySearchRec
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
