Question: Please fill in the gaps within the given code. They are marked by ? ? ? and commented with # task 1 and # task

Please fill in the gaps within the given code. They are marked by ??? and commented with # task 1 and # task 2.
The following code shall perform a binary search.
The complexity shall not exceed O(log n).
The goal is to find the position in the ascending sorted array where the element x can be found, if it is included.
For example:
Test Result
array =[3,4,5]
x =2
low =0
high = len(array)-1
result = binaryLocate(low, high, array, x)
if result !=-1:
print("Element is present at index "+ str(result))
else:
print("Not found")

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 Programming Questions!