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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum and Product of minimum and maximum element of Binary Search Tree
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Sum and Product of minimum and maximum element of an Array
- Minimum swap required to convert binary tree to binary search tree
- Find maximum and minimum element in binary tree without using recursion or stack or queue
- Min-Max Product Tree of a given Binary Tree
- Find maximum level product in Binary Tree
- Print Sum and Product of all Non-Leaf nodes in Binary Tree
- Check if max sum level of Binary tree divides tree into two equal sum halves
- Difference between Binary Tree and Binary Search Tree
- Convert a Generic Tree(N-array Tree) to Binary Tree
- Check if a binary tree is subtree of another binary tree | Set 1
- Binary Tree to Binary Search Tree Conversion
- Check if a binary tree is subtree of another binary tree | Set 2
- Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue)
- Check whether a binary tree is a full binary tree or not
- Convert a Binary Tree to Threaded binary tree | Set 2 (Efficient)
- Check whether a given binary tree is skewed binary tree or not?
- Binary Tree | Set 3 (Types of 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.