MCPcopy Create free account
hub / github.com/geekcomputers/Python / binarySearchAppr

Function binarySearchAppr

binary search.py:1–16  ·  view source on GitHub ↗
(arr, start, end, x)

Source from the content-addressed store, hash-verified

1def binarySearchAppr(arr, start, end, x):
2 # check condition
3 if end >= start:
4 mid = start + (end - start) // 2
5 # If element is present at the middle
6 if arr[mid] == x:
7 return mid
8 # If element is smaller than mid
9 elif arr[mid] > x:
10 return binarySearchAppr(arr, start, mid - 1, x)
11 # Else the element greator than mid
12 else:
13 return binarySearchAppr(arr, mid + 1, end, x)
14 else:
15 # Element is not found in the array
16 return -1
17
18
19arr = sorted(["t", "u", "t", "o", "r", "i", "a", "l"])

Callers 1

binary search.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected