Tree














































Tree



Basics of Tree Data Structure PART - 1 

  • Tree is a non-linear data structure which organizes data in a hierarchical structure and this is a recursive definition.
  • A tree is a connected graph without any circuits/cycles.

Tree Terminology-

The important terms related to tree data structure are-


1. Root-

  • The first node from where the tree originates is called as a root node.
  • In any tree, there must be only one root node.
  • We can never have multiple root nodes in a tree data structure.


Here, node A is the only root node.

 2. Edge-

  • The connecting link between any two nodes is called as an edge.
  • In a tree with n number of nodes, there are exactly (n-1) number of edges.


3. Parent-


  • The node which has a branch from it to any other node is called as a parent node.
  • In other words, the node which has one or more children is called as a parent node.
  • In a tree, a parent node can have any number of child nodes.


Here,

  • Node A is the parent of nodes B and C
  • Node B is the parent of nodes D, E and F
  • Node C is the parent of nodes G and H
  • Node E is the parent of nodes I and J
  • Node G is the parent of node K

4. Child-

  • The node which is a descendant of some node is called as a child node.
  • All the nodes except root node are child nodes.


Here,

  • Nodes B and C are the children of node A
  • Nodes D, E and F are the children of node B
  • Nodes G and H are the children of node C
  • Nodes I and J are the children of node E
  • Node K is the child of node G

5. Siblings-


  • Nodes which belong to the same parent are called as siblings.
  • In other words, nodes with the same parent are sibling nodes.


  • Nodes B and C are siblings
  • Nodes D, E and F are siblings
  • Nodes G and H are siblings
  • Nodes I and J are siblings

6. Degree-

 

  • Degree of a node is the total number of children of that node.
  • Degree of a tree is the highest degree of a node among all the nodes in the tree.

 

Example-



Here,

  • Degree of node A = 2
  • Degree of node B = 3
  • Degree of node C = 2
  • Degree of node D = 0
  • Degree of node E = 2
  • Degree of node F = 0
  • Degree of node G = 1
  • Degree of node H = 0
  • Degree of node I = 0
  • Degree of node J = 0
  • Degree of node K = 0
Remaining Tree Terminologies are discussed in my next article (Basics of Tree Data Structure PART - 2)
Please Like if you felt it useful.
If you have any doubts please mention in the Comment Section.(To Do comment Please Sign in)


More Articles of Shaik Ismail:

Name Views Likes
C++ Shutdown Using C++ Code 385 1
C++ Majority Element (LeetCode) 328 0
C++ Missing Number(LeetCode) 155 0
C++ Count set bits in an integer 551 0
C++ Power of Two Leetcode BitManipulation 446 0
C++ Single Number LeetCode Bit Manipulation 214 0
C++ Radix Sort 186 0
C++ Wave Sort 161 0
C++ Counting Sort 155 0
C++ DNF Algorithm for Sorting 0,1,2 320 0
C++ Merge Sort 157 0
C++ Quick Sort 232 0
C++ Insertion Sort 153 0
C++ Selection Sort 167 0
C++ Bubble Sort 204 0
C++ DFS for a Graph 182 0
C++ BFS in Graph 197 0
C++ Graph Representation (Adjacency list) 160 0
C++ Graph Representation 181 0
C++ Basics of Graph Data Structure 163 0
C++ Diameter of a Binary Tree 193 0
C++ Check if a binary tree is a BST or not 493 0
C++ Heap Sort 364 0
C++ Deletion in Heaps 380 0
C++ Insertion of Elements in Heap 157 0
C++ Basics of Heap Data Structure 152 0
C++ Deletion in AVL Trees 138 0
C++ AVL Rotations 238 0
C++ AVL Tree 144 0
C++ Deletion of Nodes in BST 495 0
C++ Kth Largest Element in BST 149 0
C++ Kth Smallest Element in BST 175 0
C++ Searching in BST 137 0
C++ Insertion of Nodes in BST 138 0
C++ Basics of BST Part - 1 337 0
C++ Binary Tree is a SumTree or Not 122 0
C++ Sum of all leaf nodes 126 0
C++ Identical Binary Trees 132 0
C++ Mirror Binary Tree 190 0
CPP Project or program to get six subjects marks of a student and then calculate its total, average and percentage and display them on the screen 145 0
C++ Lowest Common Ancestor 143 0
C++ Bottom View of a Binary Tree 183 0
C++ Top View of a Binary Tree 131 0
C++ Vertical Order Traversal of a Binary Tree 198 0
C++ Level Order Traversal of a Binary Tree 172 0
C++ Height of the Binary Tree (Code) 131 0
C++ Binary Tree Representation and Traversals (Code) 169 1
C++ Binary Tree 135 0
C++ Basics of Tree Data Structure PART - 2 147 0
Tree 134 1
Basics of Tree Data Structure PART - 1 98 0

Comments