This blog will soon be merged with

JavaByPatel

which explains each solution in detail, to visit new blog, click JavaByPatel

Tuesday, 9 December 2014

Binary Trees Terminology



Root: Node at the top of a tree and which has no Parents. In example above it is Node 1.

Siblings: Nodes with the same parent are called Siblings. In our case Node 2 and 3 are Siblings as they both have common parent Node 1. Node 4 and 5 are siblings as they have common parent Node 2. and so on.

Descendant: a node reachable by repeated proceeding from parent to child.
In our case Node 8 is Descendant of Node 4, Node 2 and Node 1. Similarly Node 4 is Descendant of Node 2 and Node 1.

Ancestor: a node reachable by repeated proceeding from child to pare
In our case Node 1 is Ancestor of Node 2, Node 4 and Node 8. Similarly Node 2 is Ancestor of Node 4 and Node 8.

Leaves / Leaf / External Node: Nodes with no children are called leaves.
In our case it is Node 8, 9, 5, 6, and 7.

Internal nodes: Nodes which are not leaves are called internal nodes.

In our case it is Node 1, 2, 3 and 4.

Height of a Tree: The height of a tree is the number of edges on the longest downward path between the root and a leaf.
So in that case height of our Binary Tree is 3 as between Root Node 1 and deepest Leaf Node ie either Node 8 or Node 9, edges present are 3.

                    Please Note: it is debate as some says Height of Binary Tree starts with 0 and some says it starts with 1.


Height of a Node: The height of a node is the number of edges on the longest downward path between that node and a leaf.

Size of Binary Tree: Size of a Tree is numbers of Nodes in it, in our case it is 9.

Depth / Level of Tree: Depth of a Node is distance from Root node.
    Node 4 is at depth 2.
    Node 1 is at depth 0.
    Similarly,
       Node 1 is at Level 0.
       Node 2, Node 3 is at Level 1
       Node 4, Node 5, Node 6, Node 7 is at Level 2 and so on.







No comments:

Post a Comment