Objective: – Given a binary tree , Find the max element in it.
Example:

Approach:
- Use Recursion.
- Max will the Max(root, max element in the left subtree, max element in right subtree)
- Recursively solve for the max element in the left subtree and right subtree.
Complete Code:
Output:
Max element in Binary Tree: 35
if we try to find min element with this process this is giving always 0. why?
its returning minimum as 0 since during traversal when left or right child is null, the code returns 0, to make it work for get the minimum element, handle the return 0, one quick way is return Integer.Max_Value, please follow the link below
https://ide.tutorialhorizon.com/?gistUrl=https%3A%2F%2Fgist.githubusercontent.com%2Fthmain%2F01a1337ea51b6328e2bc1a68732ede21%2Fraw%2F
thanks a lot.It was very helpful….
You are welcome, Glad it helped