Height of Heap Java
PROGRAM TO FIND HEIGHT OF A COMPLETE HEAP
OUTPUT:
2
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));
}
}
2
Comments
Post a Comment