Binary Tree
Binary Tree
A Binary Tree non linear and hierarchical data structure in which each node has at most two children, referred to as the left child
and the right child.
Representation of Binary Tree
Each node in a Binary Tree has three parts:
• Data
• Pointer to the left child
• Pointer to the right child
o AVL Tree
• An AVL Tree is a special kind of Binary Search Tree (BST) that is always balanced.
• It is named after its inventors: Adelson-Velsky and Landis
It automatically balances itself after insert or delete
• The balance factor must be -1,0,1
• Total number of leaf nodes in a binary tree = total number of nodes with 2 children + 1
• In a Binary Tree with N nodes, the minimum possible height or the minimum number of levels is Log2(N+1)
➤ If N = 7 nodes:
log₂(7 + 1) = log₂(8) = 3
So, minimum height = 3
• Node at index 1 = 10
o Left → 2×1 = 2 → 20
o Right → 2×1+1 = 3 → 30
• Node at index 2 = 20
o Left → 2×2 = 4 → 40
o Right → 2×2+1 = 5 → 50
• Node at index 3 = 30
o Left → 2×3 = 6 → 60
o Right → 2×3+1 = 7 → Not present
It fits all rules
Linked List representation:
Linked list representation of a binary tree is a method in which each
node is represented as a structure or class containing:
• The data
• A pointer to the left child
• A pointer to the right child
Node connection Based on index formulas Using left and right pointers
Best suited for Complete binary trees Any type of binary tree
Memory usage May waste memory in skewed trees Memory efficient, no wasted space
Ease of implementation Simple indexing logic Needs dynamic memory and pointers