According to Wikipedia,
The height of a tree is the length of the path from the root to the deepest node in the tree. A (rooted) tree with only one node (the root) has a height of zero (or one).
I dont get it-is it zero or one (or both)?
According to Wikipedia,
The height of a tree is the length of the path from the root to the deepest node in the tree. A (rooted) tree with only one node (the root) has a height of zero (or one).
I dont get it-is it zero or one (or both)?
Depends on convention. There isn't a "right" answer here. I was taught it's 1. But zero is just as correct.
It just an assuption you make for the recursive description of the height of a binary tree. You can consider a tree composed by just a node either with 0 height or with 1 height.
If you really want to think about it somehow you can think that
This is just to describe how much height the smallest tree has, then in any case whenever you add a descending node you will add also a related edge so it will increase accordingly.
In the example provided in wikipedia:
This tree can have height 4 (nodes) or 3 (edges). It depends if you are counting it by edges or by nodes.
depends how you want to interpret the height of a tree. in some applications, a tree with one node is interpreted as having height of one and others consider it as having height of zero.
One advantage of using a node count rather than an edge count is that it distinguishes the empty case (zero nodes, and node level) from the minimal case (one node, and a node level of one). In some cases, an empty tree will not be meaningful, but in other cases an empty try will be perfectly legitimate.