Saturday, 8 April 2017

Tree

What is Tree?

In Tree,each node points to a number of nodes. Tree is an example of a non-linear data structure. A tree structure is a way of representing the hierarchical nature of a structure in a graphical form.


  • The root of a tree is the node with no parents.
  • A node with no children is called leaf node
  • Children of same parent are called siblings (B, C, D are siblings of A, and E, F are the siblings of B).
  • A, C and G are the ancestors of K.
  • (B, C and D are the same level).
  • Depth of G is 2, A – C – G.
  • The height of B is 2 (B – F – J).


If every node in a tree has only one child (except leaf nodes) then we call such trees skew trees. If every node has only left child then we call them left skew trees. Similarly, if every node has only right child then we call them right skew trees.



No comments:

Post a Comment

Array

Program for Array Rotation 1st Method - Using temp array  - Time complexity - O(n), Space - O(d) See algo and code 2nd Method - rotate...