Consider a Binary Heap of size N. Determine the height of the heap.
Examples:
Input : N = 6๐ tree Output : 2Explanation: 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๐ ttree Output : 3Explanation: In this tree the longest path (e.g., 2 - 3 - 5 - 6) has 3 edges, so the treeโs height is 3.
Input : N = 6
Output : 2Explanation: 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 : 3Explanation: In this tree the longest path (e.g., 2 - 3 - 5 - 6) has 3 edges, so the treeโs height is 3.
Since a binary heap is a complete binary tree, its height is found using the formula floor(log2N).
2