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 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
Get step-by-step solutions from verified subject matter experts
