JavaDeveloper
JavaDeveloper

Reputation: 5660

What is the term for number of nodes from root to the leaf in Binary tree

The depth of a node is the number of edges from the root to the node. What is the term for number of nodes from root to a node including root and node ? Eg: A with right child B with a right child C. Such tree has height of 2, but some term of 3.

Upvotes: 1

Views: 190

Answers (3)

user3341765
user3341765

Reputation: 36

In the case of the example you gave (A with right child B with a right child C) would actually have a height of 3 (since root node height = 1; right child B height = 2; right child C height = 3).

I believe the term you are looking for is the depth. Again, in the example you gave, right child B depth = 1 and its right child C depth = 2.


Height: 1      A                Depth: 0
                \
                 \
Height: 2         B             Depth: 1
                   \
                    \
Height: 3            C          Depth: 2

Also, C is considered to be a descendant of B, and B is an ancestor of C.

Upvotes: 0

NRitH
NRitH

Reputation: 13903

It's simply the size of the (sub)tree whose root is A.

edited

From Wikipedia:

"A subtree of a tree T is a tree consisting of a node in T and all of its descendants in T.[c][1] Nodes thus correspond to subtrees (each node corresponds to the subtree of itself and all its descendants) – the subtree corresponding to the root node is the entire tree, and each node is the root node of the subtree it determines; the subtree corresponding to any other node is called a proper subtree (in analogy to the term proper subset)."

Upvotes: -1

jilles de wit
jilles de wit

Reputation: 7148

I don't think there is an official term for this. But because nodes in a binary tree below the root node are often called child nodes I'd suggest: generation. So in your example the tree has 3 generations.

Upvotes: 1

Related Questions