An ultimate introduction to binary tree

BLOG CREDITS THANMAI KOGATAM

Binary Tree:
● Non-linear data structure
● Maximum of two children for each parent
● Stores information in a hierarchical manner

Applications:
● Data compression
● Preparing binary heaps and binary search trees


Basic Terminologies of Binary tree (Numbering of nodes is based on above
picture):
● Root – top most node [1]
● Parent – node directly above something (3 is the parent of 6 and 7)
● Child – node directly under an element(4 and 5 are children of 2)
● Leaf Nodes – nodes with no left and right children (8,5,6,7)
● Internal Nodes -all nodes expect leaves (1,2,3,4)
● Height of a tree – no. of edges from root to the deepest leaf.(Here
height is 3)
Basic Structure of the Binary tree node:
1. Data
2. Pointer to left child
3. Pointer to right child


Code snippet of Node class(C++) :
Node{
int data;
Node* left;
Node* right;
public:
// constructor to initialize a node of value = val
Node(int val)
{
data = val;
left = right = NULL;
}