human
Can you provide a code to find a Fixed Point ( Value equal to index ) in a given array and the other steps required given the following:
Find a Fixed Point ( Value equal to index ) in a given array | Python program to check fixed point in an array using binary search.
.
Return - 1 if there is no Fixed Point.
Driver program to check above functions"
Solution in Python:
assistant
#Here is code to find a Fixed Point ( Value equal to index ) in a given array and the other steps required.
 def binarySearch ( arr , low , high ) :
	if high >= low :
		mid = ( low + high ) // 2
	if mid is arr [ mid ] :
		return mid
	if mid > arr [ mid ] :
		return binarySearch ( arr , ( mid + 1 ) , high )
	else :
		return binarySearch ( arr , low , ( mid - 1 ) )
	return - 1
arr = [ - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ]
n = len ( arr )
print ( " Fixed ▁ Point ▁ is ▁ " + str ( binarySearch ( arr , 0 , n - 1 ) ) )