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 ..... .....
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.
- Difference between Binary Heap, Binomial Heap and Fibonacci Heap
- Relationship between number of nodes and height of binary tree
- Find height of a special binary tree whose leaf nodes are connected
- Print the nodes of the Binary Tree whose height is a Prime number
- Print path from root to all nodes in a Complete Binary Tree
- Sum of the mirror image nodes of a complete binary tree in an inorder way
- Generate Complete Binary Tree in such a way that sum of non-leaf nodes is minimum
- Convert min Heap to max Heap
- Heap Sort for decreasing order using min heap
- Difference between Min Heap and Max Heap
- Tournament Tree (Winner Tree) and Binary Heap
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Check if a given Binary Tree is height balanced like a Red-Black Tree
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Print all the leaf nodes of Binary Heap
- Traversal of tree with k jumps allowed between nodes of same height
- Count the nodes of the tree which make a pangram when concatenated with the sub-tree nodes
- Check if a given Binary Tree is Heap
- Overview of Data Structures | Set 2 (Binary Tree, BST, Heap and Hash)
- Complexity of different operations in Binary tree, Binary Search Tree and AVL 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.