I'm trying to write an algorithm to check if a given binary tree is a perfect binary tree, and of course with the lowest complexity.
I was thinking to calculate the height of the tree $h$ and the number of the nodes $n$, then if $2^{h+1} -1 = n$, it's a perfect tree. But then again, it's not very efficient.
The I thought to find the minimum tree height, and maximum tree height, and if they are equal, it's a perfect tree. But also this case, isn't much of improvement.
Any idea how to make it better?