Pergunta

Below is a rooted tree, where any node C except root has one parent P

Ancestors of a node C are the nodes on path from C to root, including P,P's parent,P's grandparent, .... till root.

enter image description here

My understanding is, Tree is just a set of nodes & edges that connect these nodes. Between any two nodes there is exactly one single path. A tree does not need to have any root.

Any rooted tree MUST be a tree but any tree may not be a rooted tree.

In the below tree(not a rooted tree),

enter image description here

--

My understanding is, parent-child, depth, height, subtree, siblings, leaf-node concepts are only applied to rooted trees.

If no, then,

Is X a parent of Y? If yes, Who are the ancestors of Y?

Foi útil?

Solução

No. The concept of "parent" and "ancestor" applies to the rooted tree because one unique root is defined and since there is a connected graph there is always a path from any node to the root.

In an unrooted tree there is no root defined and therefore the concepts of "parent" and "ancestor" do not apply.

In that graph either X or Y could be labelled as the root, and if this were the case then either would be parent and ancestor accordingly.

Licenciado em: CC-BY-SA com atribuição
scroll top