Floor square root without using sqrt ( ) function : Recursive | Function to find the square root of the number N using BS ; If the range is still valid ; Find the mid - value of the range ; Base Case ; Condition to check if the left search space is useless ; Driver Code
def sqrtSearch ( low , high , N ) : NEW_LINE INDENT if ( low <= high ) : NEW_LINE INDENT mid = ( low + high ) // 2 ; NEW_LINE if ( ( mid * mid <= N ) and ( ( mid + 1 ) * ( mid + 1 ) > N ) ) : NEW_LINE INDENT return mid ; NEW_LINE DEDENT elif ( mid * mid < N ) : NEW_LINE INDENT return sqrtSearch ( mid + 1 , high , N ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return sqrtSearch ( low , mid - 1 , N ) ; NEW_LINE DEDENT DEDENT return low ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 25 ; NEW_LINE print ( sqrtSearch ( 0 , N , N ) ) NEW_LINE DEDENT