Relationship between height and size of a perfect binary tree

In the exercise for Tree.isPerfect() Mosh hints to think about the relationship stated in the title.
Based on the code provided in his solution I’ve surmised that the relationship is size = (2 ^ height + 1) - 1.

``````public boolean isPerfect() {
return size() == (Math.pow(2, height() + 1) - 1);
}
``````

However when checking on the web I’ve found that the relationship is stated as size = 2 ^ height, (since height = log size). Can anyone shed some light as to why Mosh’s relationship is slightly different?

Also I’d like to shamelessly plug the DSA Study Group. We are only a few beginners (myself included) as of now so I still vouched to ask the broader forum for feedback. Feel free to check out my other post for the discord link.

After enough searching I eventually found the answer.
At a given height of a tree the max nodes is equal to 2 ^ height.
However the max nodes in the entire tree is equal to (2 ^ height + 1) - 1.