Consider a Binary Heap of size N. We need to find height of it.
Input : N = 6 Output : 2 () / \ () () / \ / () () () Input : N = 9 Output : () / \ () () / \ / \ () () () () / \ () ()
Let the size of heap be N and height be h
If we take few examples, we can notice that the value of h in a complete binary tree is ceil(log2(N+1)) – 1.
N h --------- 1 0 2 1 3 1 4 2 5 2 ..... .....
- Relationship between number of nodes and height of binary tree
- Find height of a special binary tree whose leaf nodes are connected
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Traversal of tree with k jumps allowed between nodes of same height
- Check if a given Binary Tree is height balanced like a Red-Black Tree
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Linked complete binary tree & its creation
- Tournament Tree (Winner Tree) and Binary Heap
- Check whether a given Binary Tree is Complete or not | Set 1 (Iterative Solution)
- Iterative Boundary traversal of Complete Binary tree
- Construct Complete Binary Tree from its Linked List Representation
- Construct a complete binary tree from given array in level order fashion
- How to determine if a binary tree is height-balanced?
- Height of binary tree considering even level leaves only
- Iterative Method to find Height 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.