Given a Binary Tree, the task is to print all the Exponential Levels in the given Binary Tree.
An Exponential Level is a level whose all nodes of that levels equals to xy, & where x is a minimum possible positive constant & y is a variable positive integer.
Input: 20 / \ 9 81 / \ / \ 3 10 70 243 / \ 81 909 Output: 20 9 81 Explanation: There are 2 exponential levels: 20: 201 = 20. 9, 81: 32 = 9, 34 = 81. Input: 8 / \ 4 81 / \ / \ 5 125 625 5 / \ 81 909 Output: 8 5 125 625 5
Approach: To solve the problem mentioned above the main idea is to use Level Order Tree Traversal.
- Perform level order traversal of the given Binary tree and store each level in a vector.
- Then, in each level, if every node can be expressed in the form of xy, for y ≥ 0.
- If any value of the node of this level is not equal to xy, then skip to the next level.
- Print all such levels in which the above condition is true.
Below is the implementation of the above approach:
20 9 81 3 9 81 243
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Print all K-sum levels in a Binary Tree
- Print Levels of all nodes in a Binary Tree
- Print all Co-Prime Levels of a Binary Tree
- Print all nodes between two given levels in Binary Tree
- Print all Palindromic Levels Of a Binary Tree
- Print all Prime Levels of a Binary Tree
- Print Binary Tree levels in sorted order | Set 2 (Using set)
- Print Binary Tree levels in sorted order
- Print odd positioned nodes of odd levels in level order of the given binary tree
- Print odd positioned nodes of even levels in level order of the given binary tree
- Print even positioned nodes of even levels in level order of the given binary tree
- Print even positioned nodes of odd levels in level order of the given binary tree
- Print updated levels of each node of a Complete Binary Tree based on difference in weights of subtrees
- Count of exponential paths in a Binary Tree
- Print the nodes at odd levels of a tree
- Averages of Levels in Binary Tree
- Left-Right traversal of all the levels of Binary tree
- Maximum sum of non-leaf nodes among all levels of the given binary tree
- Maximum sum of leaf nodes among all levels of the given 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.