Height of Heap Java

PROGRAM TO FIND HEIGHT OF A COMPLETE HEAP



import java.lang.*;
 
class GFG {
     
    // Function to calculate height
    static int height(int N)
    {
        return (int)Math.ceil(Math.log(N +
                    1) / Math.log(2)) - 1;
    }
 
    // Driver Code
    public static void main(String[] args)
    {
        int N = 6;
        System.out.println(height(N));
    }
}


OUTPUT:
2

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java