Given a positive integer N, the task is to find the count of edges of a perfect binary tree with N levels.
Input: N = 2 Output: 2 1 / \ 2 3 Input: N = 3 Output: 6 1 / \ 2 3 / \ / \ 4 5 6 7
Approach: It can be observed that for the values of N = 1, 2, 3, …, a series will be formed as 0, 2, 6, 14, 30, 62, … whose Nth term is 2N – 2.
Below is the implementation of the above approach:
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.
- Reverse alternate levels of a perfect binary tree
- Reverse alternate levels of a perfect binary tree using Stack
- Number of edges in mirror image of Complete binary tree
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Averages of Levels in Binary Tree
- Print all K-sum levels in a Binary Tree
- Print all nodes between two given levels in Binary Tree
- Print all Exponential Levels of a Binary Tree
- Left-Right traversal of all the levels of Binary tree
- Print Levels of all nodes in a Binary Tree
- Print all Palindromic Levels Of a Binary Tree
- Print all Co-Prime Levels of a Binary Tree
- Print all Prime Levels of a Binary Tree
- Print Binary Tree levels in sorted order | Set 2 (Using set)
- Maximum sum of leaf nodes among all levels of the given binary tree
- Print Binary Tree levels in sorted order
- Maximum sum of non-leaf nodes among all levels of the given binary tree
- Construct XOR tree by Given leaf nodes of Perfect Binary Tree
- Print odd positioned nodes of odd levels in level order of the given binary tree
- Print even positioned nodes of even levels in level order 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 email@example.com. 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.