Tree


Tree

Trees are used to showcase hierarchical relationships. It is a non linear data structure. A binary tree is a tree where each node can have atmost 2 children. Each element is known as a node and contains 3 parts: Data, pointer to the left and the right child.

Various types of Binary trees are as follows:

  • Full Binary Tree – Each node has 0 or 2 children.
  • Perfect Binary Tree – All inside nodes have 2 children and all leaves are at same level.
  • Complete Binary Tree – Every level is filled and is as far to the left as possible.

Components of a tree are as follows:

  • Root
  • Parent
  • Child
  • Subtree
  • Depth
  • Height
  • Degree

Components of a tree are as follows:

  • Searching
  • Indexing
  • Networking
  • Inheritance
  • Shortest path
  • Storage as hierarchy

Tree traversals can be done in following ways:

  • Depth First Search
  • Breadth First Search
  • Pre Order Traversal
  • Post Order Traversal

Key points about Tree data structure:

  • A tree data structure comprises nodes, items or entities joined together to represent or simulate a hierarchy.
  • Because it does not store data in sequential order, a tree data structure is a non-linear data structure. Because the pieces in a Tree are grouped at numerous levels, it is a hierarchical structure.
  • The root node in a Tree data structure is the topmost node.