Height of a complete binary tree (or Heap) with N nodes
Last Updated : 4 Feb, 2026
Consider a Binary Heap of size N. Determine the height of the heap.
Examples:
Input : N = 6
Output : 2 Explanation: The height of a tree is the number of edges on the longest path from root to leaf. Here, the longest path (e.g., 1 - 3 - 5) has 2 edges, so the tree’s height is 2. Input : N = 9
Output : 3 Explanation: In this tree the longest path (e.g., 2 - 3 - 5 - 6) has 3 edges, so the tree’s height is 3.