I need help with the theory on calculating the height of a binary tree, typically the notation.
I have read the following article:
Calculating height of a binary tree
And one of the posts gives the following notation:
height(node) = max(height(node.L), height(node.R)) + 1
Let's assume I have the following binary tree:
10
/ \
5 30
/ \ / \
4 8 28 42
Do I therefore calculate the max value on the left node (8) and the max node on the right (42) and then add 1? I don't quite understand how this notation works in order to calculate the height of the tree.
height
calls itself until it gets to the bottom of each branch of the tree.node.L
by thenode.R
What would be the height of the current tree given, as an example?