Get maximum left node in binary tree | Get max of left element using Inorder traversal ; Return maximum of three values 1 ) Recursive max in left subtree 2 ) Value in left node 3 ) Recursive max in right subtree ; Utility class to create a new tree node ; Driver Code ; Let us create binary tree shown in above diagram ; 7 / \ 6 5 / \ / \ 4 3 2 1
def maxOfLeftElement ( root ) : NEW_LINE INDENT res = - 999999999999 NEW_LINE if ( root == None ) : NEW_LINE INDENT return res NEW_LINE DEDENT if ( root . left != None ) : NEW_LINE INDENT res = root . left . data NEW_LINE DEDENT return max ( { maxOfLeftElement ( root . left ) , res , maxOfLeftElement ( root . right ) } ) NEW_LINE DEDENT class newNode : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = self . right = None NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT root = newNode ( 7 ) NEW_LINE root . left = newNode ( 6 ) NEW_LINE root . right = newNode ( 5 ) NEW_LINE root . left . left = newNode ( 4 ) NEW_LINE root . left . right = newNode ( 3 ) NEW_LINE root . right . left = newNode ( 2 ) NEW_LINE root . right . right = newNode ( 1 ) NEW_LINE print ( maxOfLeftElement ( root ) ) NEW_LINE DEDENT