Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Tree Concept: Defining ancestors

enter image description here

What defines an ancestor? More specifically, would E be an ancestor to H? Or is it more simply that F,C,A are ancestors to H? Maybe even G? I would just like to clear up this simple concept.

like image 230
Pat Murray Avatar asked Apr 10 '12 19:04

Pat Murray


People also ask

What are ancestors in a tree?

A node that is connected to all lower-level nodes is called an "ancestor". The connected lower-level nodes are "descendants" of the ancestor node.

What are basic tree concepts?

A tree is a hierarchical data structure defined as a collection of nodes. Nodes represent value and nodes are connected by edges. A tree has the following properties: The tree has one node called root. The tree originates from this, and hence it does not have any parent.

How do you find the ancestors of a tree node?

Recursive Solution The idea is to traverse the tree in a postorder fashion and search for a given node in the tree. For any node, if the given node is found in either its left subtree or its right subtree, then the current node is an ancestor of it.

What is a proper ancestor?

proper ancestor of n. A proper ancestor of n is any node y such that node y is an ancestor of node n and y is not the same node as n. descendent of n. Any node y for which n is an ancestor of y. Every node is an descendent of itself.


1 Answers

E is not an ancestor of H. It's an uncle because it's a sibling of F, which is the parent of H.

F,C,A are ancestors of H. That's true.

G is not relevant to H at all.

Tree structure relationship notation can be found here (according to Wikipedia)

  • A node's "parent" is a node one step higher in the hierarchy (i.e. closer to the root node) and lying on the same branch.
  • "Sibling" ("brother" or "sister") nodes share the same parent node.
  • A node's "uncles" are siblings of that node's parent.
  • A node that is connected to all lower-level nodes is called an "ancestor". The connected lower-level nodes are "descendants" of the ancestor node.
like image 102
Thiem Nguyen Avatar answered Oct 22 '22 05:10

Thiem Nguyen