Question: Recursive Binary Search - binary_search(data, item, offset) Takes a sorted list, data , and performs a recursion binary search of data for the element item

Recursive Binary Search - binary_search(data, item, offset)

Takes a sorted list, data, and performs a recursion binary search of data for the element item using Python 3.

If found, returns the index where the item is found

If not found, return None

offset is a variable used for recursive calls to record the offset from the original data. The function will always be initially called with this set to 0

The Python Standard library contains functions/methods for searching, sorting, and splitting. You are not permitted to use these or any other functions/methods/objects not covered in class.

You are permitted to use len(), the list append(), and range()

Examples

>>> binary_search([0, 3, 5], 5, 0) 2 >>> binary_search([0, 3, 5, 7], 0, 0) 0 >>> binary_search([0, 3, 5, 7], 42, 0) # returns None 

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!