Given a Binary Tree. The task is to write a program to find the product of all of the nodes of the given binary tree.
In the above binary tree,
Product = 15*10*20*812*16*25 = 974400000
The idea is to recursively:
- Find product of left subtree.
- Find product of right subtree.
- Mutiply the product of left and right subtrees with current node’s data and return.
Below is the implementation of the above approach:
Product of all the nodes is: 40320
Time complexity : O(n)
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.
- Product of all leaf nodes of binary tree
- Print Sum and Product of all Non-Leaf nodes in Binary Tree
- Construct XOR tree by Given leaf nodes of Perfect Binary Tree
- Product of nodes at k-th level in a tree represented as string
- Product of nodes at k-th level in a tree represented as string using Recursion
- Sum of all nodes in a binary tree
- Sink even nodes in Binary Tree
- Sum of all leaf nodes of binary tree
- Sum of nodes in the right view of the given binary tree
- Sum of nodes in top view of binary tree
- Sink Odd nodes in Binary Tree
- Sum of all the Boundary Nodes of a Binary Tree
- XOR of path between any two nodes in a Binary Tree
- Sum of all nodes at Kth level in a Binary Tree
- Min-Max Product Tree of a given Binary Tree
- Find maximum among all right nodes in Binary Tree
- Print all internal nodes of a Binary tree
- Sum of nodes in bottom view of Binary Tree
- Sum of all the child nodes with even grandparents in a Binary Tree
- Check if two nodes in a Binary Tree are siblings
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.