Trees and Binary Trees
Trees and Binary Trees
Binary Trees
Objective of the sesson
• Tree
– Basic Terminologies
• Binary Tree
– Binary Tree – Representation
• Linear Data Structure and Non- Linear Data
Structure
Nature View of a Tree
leaves
branches
root
Computer Scientist’s View
root
leaves
branches
nodes
TREES
• Trees are one of the important non- Linear data
structure.
• A tree is a Multilevel data structure that represent a
hierarchical relationship between the Set of
individual elements called nodes.
• Each tree structure starts with a node Which is called
the root node of the Tree.
Tree Terminology
• Root: node without parent (A)
• Degree of a tree: the
• Siblings: nodes share the same
parent maximum number of its node.
• Internal node: node with at least • Subtree: tree consisting of a
one child (A, B, C, F) node and its descendants
• External node (leaf ): node
without children (E, I, J, K, G, H, D)
A
• Ancestors of a node: parent,
grandparent, grand-grandparent,
etc.
• Descendant of a node: child, B C D
grandchild, grand-grandchild, etc.
• Depth of a node: number of
ancestors E F G H
• Height of a tree: maximum depth
of any node (3)
• Degree of a node: the number of I J K
its children subtree
Binary Tree
• A tree in which every node can have a
maximum of two children is called as Binary
Tree.
Full Binary Tree
• A binary tree in which every node has either
two or zero number of children is called Full
Binary Tree
Complete Binary Tree
• A binary tree in which every internal node has exactly two
children and all leaf nodes are at same level is called
Complete Binary Tree. Complete binary tree is also called
as Perfect Binary Tree
• Number of nodes = 2d+1 – 1
• Number of leaf nodes = 2d
• Where, d – Depth of the tree
Left Skewed and Right Skewed
Trees
• Binary tree has only left sub trees - Left
Skewed Trees
• Binary tree has only right sub trees - Right
Skewed Trees
Binary Tree Representation
1. Sequential representation using arrays
2. List representation using Linked list
Sequential representation