text_plain_output_1.png
def binary_search_recursive(array, element, start, end):
    if start > end:
        return -1
    mid = (start + end) // 2
    if element == array[mid]:
        return mid
    if element < array[mid]:
        return binary_search_recursive(array, element, start, mid - 1)
    else:
        return binary_search_recursive(array, element, mid + 1, end)

def linearsearch(arr, x):
    for i in range(len(arr)):
        if arr[i] == x:
            return i
    return -1
arr = ['10', '20', '30', '40', '50', '60', '70']
x = '50'

def binarySearch(arr, left, right, x):
    if right >= left:
        mid = left + (right - left) // 2
        if arr[mid] == x:
            return mid
        elif arr[mid] > x:
            return binarySearch(arr, left, mid - 1, x)
        else:
            return binarySearch(arr, mid + 1, right, x)
    else:
        return -1
arr = [10, 20, 30, 40, 50, 60, 70]
x = 50
result = binarySearch(arr, 0, len(arr) - 1, x)
if result != -1:
    print('Element is present at index % d' % result)
else:
    print('Element is not present in array')