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 ..... .....
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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Height of binary tree considering even level leaves only
- Heap Sort for decreasing order using min heap
- Binary Heap
- Binary Tree | Set 3 (Types of Binary Tree)
- Segment Tree | Set 1 (Sum of given range)
- Sort a nearly sorted array using STL
- Python Code for time Complexity plot of Heap Sort
- Priority Queue in Python
- Priority queue of pairs in C++ (Ordered by first)
- Kth smallest element after every insertion