Given a Binary Tree. The task is to find the sum and product of maximum and minimum element in it.
For example, sum of the maximum and minimum element in the following Binary Tree is 10 and the product is 9.
The idea is to traverse the tree and find the maximum and minimum elements in the tree and print their product and sum.
To find the maximum element in the Binary Tree, recursively traverse the tree and return the maximum of below three:
- Current Node’s data.
- Maximum in node’s left subtree.
- Maximum in node’s right subtree.
Similarly, we can find the minimum element in the Binary tree by comparing three values.
Below program illiustrate the above approach:
Sum of Maximum and Minimum element is 12 Product of Maximum and Minimum element is 11
- Sum and Product of minimum and maximum element of Binary Search Tree
- Find maximum and minimum element in binary tree without using recursion or stack or queue
- Sum and Product of minimum and maximum element of an Array
- Find maximum level product in Binary Tree
- Find maximum (or minimum) in Binary Tree
- Minimum and maximum node that lies in the path connecting two nodes in a Binary Tree
- Minimum swap required to convert binary tree to binary search tree
- Product of all nodes in a Binary Tree
- Product of all leaf nodes of binary tree
- Product of minimum edge weight between all pairs of a Tree
- Print Sum and Product of all Non-Leaf nodes in Binary Tree
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Find the closest element in Binary Search Tree
- Maximum spiral sum in Binary Tree
- Maximum width of a binary tree
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.