human
Check for Majority Element in a sorted array | If x is present in arr [ low ... high ] then returns the index of first occurrence of x , otherwise returns - 1.
Check if arr [ mid ] is the first occurrence of x . arr [ mid ] is first occurrence if x is one of the following is true : ( i ) mid == 0 and arr [ mid ] = = x ( ii ) arr [ mid - 1 ] < x and arr [ mid ] == x.
This function returns true if the x is present more than n / 2 times in arr [ ] of size n.
Find the index of first occurrence of x in arr [ ].
If element is not present at all , return false.
check if the element is present more than n / 2 times"
Solution in Python:
 What is a code to check for Majority Element in a sorted array and the other steps required?
assistant
#Here is code to check for Majority Element in a sorted array and the other steps required.
 def _binarySearch ( arr , low , high , x ) :
	if high >= low :
		mid = ( low + high ) // 2
		if ( mid == 0 or x > arr [ mid - 1 ] ) and ( arr [ mid ] == x ) :
			return mid
		elif x > arr [ mid ] :
			return _binarySearch ( arr , ( mid + 1 ) , high , x )
		else :
			return _binarySearch ( arr , low , ( mid - 1 ) , x )
	return - 1
def isMajority ( arr , n , x ) :
	i = _binarySearch ( arr , 0 , n - 1 , x )
	if i == - 1 :
		return False
	if ( ( i + n // 2 ) <= ( n - 1 ) ) and arr [ i + n // 2 ] == x :
		return True
	else :
		return False