Question: Write a function called modified_binary_search that will take a list, a value, a lower range, and an upper range as arguments. Then, perform the binary
Write a function called modified_binary_search that will take a list, a value, a lower range, and an upper range as arguments. Then, perform the binary search in the specified range (From lower range to upper range) of that list. If the value is found in the specified range of the list, then return the index of the FIRST occurrence of the value If the value is not found in the specified range of the list, then return -99999 You will only search in the specified range; you must not search beyond the specified range. ================================================
Function Call 1: print(modified_binary_search([2,3,5,6,6,11,13,15,19,21,44,49,56],19, 1, 11))
Sample Output 1: 8
================================================
Function Call 2: print(modified_binary_search( [2,3,5,6,6,11,13,15,19,21,44,49,56], 6, 1, 11))
Sample Output 2: 3
================================================
Function Call 3: print(modified_binary_search( [2,3,5,6,6,11,13,15,19,21,44,49,56], 56, 1, 8))
Sample Output 3: -99999
================================================
Function Call 4: print(modified_binary_search([2,3,5,6,6,11,13,15,19,21,44,49,56],48, 1,11))
Sample Output 4: -99999
Explanation: In the first function call the first occurrence value was found on the specified range (from index 1 to index 11) at index 5. Therefore 5 was returned. In the second function call the first occurrence value was found on the specified range (from index 1 to index 11) at index 3. Therefore 3 was returned. In the third function call the value 56 is present on the list but not in the specified range (from index 1 to index 8), therefore, -99999 was returned. Again, in the last function call the value was not found in the specified range and hence -99999 was returned.

Write a function called modified_binary_search that will take a list, a value, a lower range, and an upper range as arguments. Then, perform the binary search in the specified range (From lower range to upper range) of that list If the value is found in the specified range of the list, then return the index of the FIRST occurrence of the value If the value is not found in the specified range of the list, then return -99999 You will only search in the specified range: you must not search beyond the specified range Function Call 1: print(modified_binary_search([2,3,5,6.6.11.13,15.19.21.44.49.56], 19. 1. 11)) Sample Output 1: 8 Function Call 2: print(modified_binary_search(2.3,5,6,6,11,13,15,19.21.44.49.56], 6. 1. 11) Sample Output 2: 3 ======= Function Call 3: print(modified_binary_search([2,3,5,6,6,11,13,15,19,21.44.49.56], 56, 1, 8)) Sample Output 3: -99999 ====== Function Call 4: print(modified_binary_search([2,3,5,6.6.11.13,15,19,21.44.49,58].48. 1.11) Sample Output 4: -99999 Explanation: In the first function call the first occurrence value was found on the specified range (from index 1 to index 11) at index 5. Therefore 5 was returned. In the second function call the first occurrence value was found on the specified range (from index 1 to index 11) at index 3. Therefore 3 was returned. In the third function call the value 56 is present on the list but not in the specified range (from index 1 to index 8), therefore, -99999 was returned. Again, in the last function call the value was not found in the specified range and hence -99999 was returned
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
