Question: Python Write a function named binary_search_descending (numbers, target_value) which takes a list of numbers which are in descending order and an integer value as parameters.

Python Write a function named binary_search_descending (numbers, target_value) which takes a listPython

Write a function named binary_search_descending (numbers, target_value) which takes a list of numbers which are in descending order and an integer value as parameters. The function searches the list of numbers for the parameter target value using a Binary Search and returns a tuple containing the position of the target value and the number of times the middle index was calculated. If the list does not contain the target value, the function should return a tuple containing - 1 and the number of times the middle index was calculated. Note: You can assume that the list is not empty and contains unique elements. You may not use Python's built in index0 or find methods. For example: Test Result numbers = [47, 42, 35, 33, 24, 23, 22, 21, 20, 19, 18, 16, 13, 12, 10] (10, 4) print(binary_search_descending(numbers, 18)) (-1, 3) numbers = [93, 78, 61, 54, 18, 13] print(binary_search_descending(numbers, 10))

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!