Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python 3, with screenshots please The template is like the following def binarySearch (listNumbers, low, high, key): # Test array def main(): array_for_test =

In python 3, with screenshots please

image text in transcribed

The template is like the following

def binarySearch (listNumbers, low, high, key):

# Test array def main(): array_for_test = [-8,-2,1,3,5,7,9] print(binarySearch(array_for_test,0,len(array_for_test)-1,9)) print(binarySearch(array_for_test,0,len(array_for_test)-1,-8)) print(binarySearch(array_for_test,0,len(array_for_test)-1,4)) main()

You will need to implement a recursive binarySearch() function which takes 4 arguments: listNumbers, which is an array assumed to contain elements in ascending order; low and high, which specify the range we want to search in the array; key, which is the element we are searching for. The function should return the index of the searched element if the element is found, or return -1 if the element is not in the array. Test you function as follows: # Test array def main(): array_for test -8,-2,1,3,5,7,9 print (binarySearch(array_for_test,e,len (array_for_test)-1,9)) print (binarySearch(array_for test,e,1en(array_for_test)-1,-8)) print (binarySearch (array_for_test,0,len(array_for_test)-1,4)) main() The output for these three cases should be 6, 0, -1. Use the debugger to trace the recursion calls to figure out what is happening

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions