Mathematics of height and nodes in Trees and Heaps
The height of a node in tree:
- is the length of the path from that node to the deepest node in the tree.
- is zero for a tree with only one node (i.e. root node).
The height of tree:
- is the maximum height among all the nodes in the tree.
- is not the same as the height of a node in a tree unless, it is a root node.
- is equal to the depth of the tree (in value but not in concept and it can be different for height of node).
- is represented as h, here.
Now, let's see the height:
4️⃣ - > Height = 2 for all nodes at this level
/ \
3️⃣ 5️⃣ - > Height = 1 for all nodes at this level
/ \ / \
1️⃣ 2️⃣ 6️⃣ 7️⃣ - > Height = 0 for all nodes at this level
3
.jpg)
.jpg)