binary_search(A, l, r, q):
	if l > r:
	    return false
	m = floor((l + r) / 2)
	
	if A[m] == q:
		return m
    
    if A[m] > q:
	    return binary_search(A, l, m - 1, q)
	else:
		return binary_search(A, m + 1, r, q)
  • Input:
    • : a sorted (non-decreasing) array of size
    • Initial call: ,
    • : the query element
  • Output:
    • The index of in if it exists, otherwise
  • Time complexity: