Question: 3 . 2 . 1 : Recursive algorithm: Search String target _ item and a list of alphabetically sorted strings are read from input. Complete

3.2.1: Recursive algorithm: Search
String target_item and a list of alphabetically sorted strings are read from input. Complete the find_middle() function:
If target_item is alphabetically before mid_value (the element at index mid_index of the list), output 'Search lower half' and recursively call find_middle() to find target_item in the lower half of the range.
Otherwise, output 'Search upper ha
def find_middle(search_list, target_item, start_index, end_index):
range_size =(end_index - start_index)+1
mid_index =(start_index + end_index)//2
mid_value = search_list[mid_index]
if target_item == mid_value:
print(f'{target_item} is found at index {mid_index}')
elif range_size ==1:
print(f'{target_item} is not in the list')
else:
''' Your code goes here '''
target_item = input()
data_list = input().split()
find_middle(data_list, target_item, 0, len(data_list)-1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!