SlideShare a Scribd company logo
2
Most read
4
Most read
10
Most read
TREES
A Non Linear Data Structure in which data items have hierarchical
relationship
Definition:
A tree can be theoretically defined as a finite set of one or more data
items (or nodes) such that :
1. There is a special node called the root of the tree.
2. Other nodes are partitioned into number of mutually exclusive (i.e.,
disjoined) subsets each of which is itself a tree, are called sub tree.
TREE Terminology
Root
A specially designed node in a tree
It is the first node in the tree
In above Fig. A is root node
Node
Each data item in a tree is called a node
It specifies the data and links to other nodes
A
B C
D E
Root
Root
Leave
Leave
Computational Real Tree
F
G
Parent Node
Child Node
A
B C
D E
Root
Leave
Computational
F
G
A
B C
D E
Root
Leave
F
G
Level 0
Level 1
Level 2
Degree of a Node
Number of sub-trees of a node
Degree of A node = 2
Degree of B node = 3
Degree of C node = 1
Degree of D node = 0
Degree of E node = 0
Degree of F node = 0
Degree of G node = 0
Degree of a Tree
The maximum degree of node in a tree.
Eg. The degree of above tree is 3
All other nodes can have <= degree of nodes
Means a node in this tree can have (0/ 1/2/3) no. of nodes
Terminal Node (Leaf node)
A node with degree 0 (no child)
Eg. G, D, E, and F are leaf nodes
Intermediate node
A node with non-zero degree
Eg. B and C nodes
Levels in Tree
A tree is structured in levels
Point to Remember
IF a node is at level n then its child will be at n+1 level
Depth/ Height of a Tree
Maximum level of any node in a given tree
Eg. Height of tree = 2
R
B C
D E
Root
F
G
T1 T2
A
B C
D
E F
G
Binary
A
B C
D
E F
G
H J
I
K
Binary Tree
BINARY TREE
Definition:
A Binary Tree is a tree in which
A node can have only(at most) 2 child nodes ( 0
child/ 1 child/ 2 childs)
The two children are called ‘Left Child’ and ‘Right
Child’ respectively.
A binary tree T is defined as a finite set of elements,
called nodes, such that-
T is empty, if T has no nodes (called empty tree/ null tree)
T contains a special node R, called Root node of T, and other nodes of
T, form an ordered pair of disjoint binary trees T1 and T2.
T1 and T2 are called Left and Right sub-trees of R.
If T1 is non empty, then its root is called Left Successor(child) of R
If T2 is non empty, then its root is called Right Successor(child) of R
Above Trees are Binary Trees. Now consider the following definition-
Strictly Binary Tree
A binary tree is said to be strictly binary tree if,
All of its non-leaf nodes in a binary tree has non empty left and
right sub-tree.
A
B C
D
E F
G
Strictly Binary Tree
A
B C
D
E F
G
H J
I
K
Binary Tree
*
+ C
B
A
Every node in the strictly binary tree can have either no children
or two children.
They are also called 2-tree or extended binary tree
Point to Remember
A strictly binary tree with n leaves always contains 2n– 1 nodes
Application of Binary Tree (2-Tree)
The main application of a 2-tree is to represent and compute any
algebraic expression using binary operation.
Consider following expression:
E = (( a + b ) * c)
E can be represented by using 2-Tree-
This is called Expression Tree. .
/
X Y
*
- e
d
c
/
X Y
+
b
a
/
+ *
b
a -
e
d
c
A
B C
D
E F
G
Complete Binary Tree
How to create Expression Tree?
Consider the given Expression-
E = a + b/c – d *e
1. Put parenthesis in the expression (if missing)
2. Find the center of the expression
E= (a + b) / ( (c – d ) *e )
X=(a + b)
Y=( (c – d ) *e )
E= X/Y
3. Make the center operator as Root node
4. Now expand X and Y in Tree
Complete Binary Tree
A complete binary tree at depth ‘d’ is the
strictly binary tree, where all the leaves are
at level d.
A
B C
D
E F
G
Complete Binary Tree
A
B
G
Binary Tree
A
B C
F
E
G
D
Complete Binary Tree
I
H K
J M
L O
N
Point to Remember
A binary tree with n nodes, n > 0, has exactly n – 1 edges
A binary tree of depth d, d > 0, has at least d and at most 2d – 1 nodes
in it.
If a binary tree contains n nodes at level L, then it can contains at
most 2n nodes at level L + 1
A complete binary tree of depth d is the binary tree of depth d
contains exactly 2 L nodes at each level L between 0 and d
A
B
G
Left Skewed Binary Tree
A
B
G
Right Skewed Binary Tree
If a binary tree has only left sub trees, then it is called left skewed
binary tree.
If a binary tree has only right sub trees, then it is called right skewed
binary tree.
A
B C
E F
G
BINARY TREE REPRESENTATION
There are two ways of representing binary tree T in memory :
1. Sequential representation using arrays
2. Linked list representation
ARRAY REPRESENTATION
1. An array can be used to store the nodes of a binary tree.
2. The nodes stored in an array of memory can be accessed
sequentially.
3. Suppose a binary tree T of depth d. Then at most
2d – 1 nodes can be there in T.
4. So an array of size 2d
-1 is required to represent
T.
Eg. Consider above binary tree of depth 3. Then 2d
-1 = 23
– 1 = 7. Then
the array Tree[7] is declared to hold the nodes.
Array representation of above tree is-
0 1 2 3 4 5 6
A B C G E F
A B C G E F
Children of A shaded
A B C G E F
Children of B shaded
A B C G E F
Children of C shaded
Point to Remember
1. The parent of a node having index n can be obtained by the
formula-
Parent = (n – 1)/2
Parent = (index of child node – 1)/2
Eg. C is located at index 2 so n=2; parent of C is located at –
(2-1)/2= ½ = 0.5 = 0 index; means it is A.
Parent of E is located at (4-1)/2 = 3/2 = 1.5 = 1; means it is B.
2. The left child of a node having index n can be obtained by the
formula-
Left child = (2n+1)
Left Child = (2 * Index of Parent) + 1
Eg. Left child of B is = 2*index of B +1 = (2*1)+1 = 2+1=3
3. The right child of a node having array index n can be obtained by
the formula-
Right child = (2n + 2)
Right Child = (2 * index of parent) + 2
Eg. Right child of C is = (2*index of C) +2 = (2*2)+2 = 6
4. If the left child is at array index n, then its right sibling is at (n +
1).
Right child = (n + 1)
Right Child = ( index of left child + 1 )
5. Similarly, if the right child is at index n, then its left sibling is at
(n – 1)
Left child = (n - 1)
Left Child = ( index of right child - 1 )

More Related Content

What's hot (20)

PPSX
Data Structure (Tree)
Adam Mukharil Bachtiar
 
PPTX
Data structure - Graph
Madhu Bala
 
PPT
Binary tree
Rajendran
 
PPTX
AVL Tree Data Structure
Afaq Mansoor Khan
 
PPT
Binary trees
Amit Vats
 
PPTX
Binary tree
Afaq Mansoor Khan
 
PPTX
Tries data structures
Jothi Ramasamy
 
PPT
Floyd Warshall Algorithm
InteX Research Lab
 
PPT
Spanning trees
Shareb Ismaeel
 
PPT
1.1 binary tree
Krish_ver2
 
PPTX
Binary Search Tree in Data Structure
Meghaj Mallick
 
PPTX
Terminology of tree
RacksaviR
 
PPTX
Graph traversals in Data Structures
Anandhasilambarasan D
 
PPTX
B tree
Tech_MX
 
PPTX
Data structures trees - B Tree & B+Tree.pptx
MalligaarjunanN
 
PDF
Dataflow Analysis
Eelco Visser
 
PPTX
Doubly Linked List
Ninad Mankar
 
PPTX
single linked list
Sathasivam Rangasamy
 
PPTX
Discrete Mathematics Tree
Masud Parvaze
 
PPT
B trees in Data Structure
Anuj Modi
 
Data Structure (Tree)
Adam Mukharil Bachtiar
 
Data structure - Graph
Madhu Bala
 
Binary tree
Rajendran
 
AVL Tree Data Structure
Afaq Mansoor Khan
 
Binary trees
Amit Vats
 
Binary tree
Afaq Mansoor Khan
 
Tries data structures
Jothi Ramasamy
 
Floyd Warshall Algorithm
InteX Research Lab
 
Spanning trees
Shareb Ismaeel
 
1.1 binary tree
Krish_ver2
 
Binary Search Tree in Data Structure
Meghaj Mallick
 
Terminology of tree
RacksaviR
 
Graph traversals in Data Structures
Anandhasilambarasan D
 
B tree
Tech_MX
 
Data structures trees - B Tree & B+Tree.pptx
MalligaarjunanN
 
Dataflow Analysis
Eelco Visser
 
Doubly Linked List
Ninad Mankar
 
single linked list
Sathasivam Rangasamy
 
Discrete Mathematics Tree
Masud Parvaze
 
B trees in Data Structure
Anuj Modi
 

Similar to Tree terminology and introduction to binary tree (20)

PPT
358 33 powerpoint-slides_10-trees_chapter-10
sumitbardhan
 
PPTX
Introduction to tree ds
Viji B
 
PPTX
NON-LINEAR DATA STRUCTURE-TREES.pptx
Rajitha Reddy Alugati
 
PPT
Unit 3.ppt
JITTAYASHWANTHREDDY
 
PPTX
Lecture 21_Trees - I.pptx
fizzaahmed9
 
PPTX
Data structure using c module 2
smruti sarangi
 
PPTX
Data Structure of computer science and technology
bhaskarsai499
 
PPT
Data Structures 4
Dr.Umadevi V
 
PPT
Lecture 5 tree.pptx
Abirami A
 
PDF
Chapter 5_Trees.pdf
ssuser50179b
 
PPT
Final tree.ppt tells about tree presentation
nakulvarshney371
 
PPTX
Tree.pptx
worldchannel
 
PDF
8.haftajava notlarıiçeriyordökumanlar.pdf
Smeyyeztrk10
 
PPT
Tree 11.ppt
DEEPAK948083
 
PPTX
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
HamzaUsman48
 
PPTX
Tree Introduction.pptx
RahulAI
 
PPTX
Binary Trees.pptx module 122img 787554yau
rithusagar5
 
PPTX
Lecture 8 data structures and algorithms
Aakash deep Singhal
 
PDF
Module - 5_Trees.pdf
AnuradhaJadiya1
 
PPTX
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DRCARIBOU
 
358 33 powerpoint-slides_10-trees_chapter-10
sumitbardhan
 
Introduction to tree ds
Viji B
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
Rajitha Reddy Alugati
 
Lecture 21_Trees - I.pptx
fizzaahmed9
 
Data structure using c module 2
smruti sarangi
 
Data Structure of computer science and technology
bhaskarsai499
 
Data Structures 4
Dr.Umadevi V
 
Lecture 5 tree.pptx
Abirami A
 
Chapter 5_Trees.pdf
ssuser50179b
 
Final tree.ppt tells about tree presentation
nakulvarshney371
 
Tree.pptx
worldchannel
 
8.haftajava notlarıiçeriyordökumanlar.pdf
Smeyyeztrk10
 
Tree 11.ppt
DEEPAK948083
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
HamzaUsman48
 
Tree Introduction.pptx
RahulAI
 
Binary Trees.pptx module 122img 787554yau
rithusagar5
 
Lecture 8 data structures and algorithms
Aakash deep Singhal
 
Module - 5_Trees.pdf
AnuradhaJadiya1
 
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DRCARIBOU
 
Ad

More from jyoti_lakhani (20)

PPSX
CG02 Computer Graphic Systems.ppsx
jyoti_lakhani
 
PPTX
Projections.pptx
jyoti_lakhani
 
PPSX
CG04 Color Models.ppsx
jyoti_lakhani
 
PPSX
CG03 Random Raster Scan displays and Color CRTs.ppsx
jyoti_lakhani
 
PPTX
CG02 Computer Graphic Systems.pptx
jyoti_lakhani
 
PPSX
CG01 introduction.ppsx
jyoti_lakhani
 
PDF
Doubly linked list
jyoti_lakhani
 
PDF
Double ended queue
jyoti_lakhani
 
PDF
Priority queue
jyoti_lakhani
 
PDF
Ds006 linked list- delete from front
jyoti_lakhani
 
PPSX
Ds06 linked list- insert a node after a given node
jyoti_lakhani
 
PPSX
Ds06 linked list- insert a node at end
jyoti_lakhani
 
PPSX
Ds06 linked list- insert a node at beginning
jyoti_lakhani
 
PPSX
Ds06 linked list- intro and create a node
jyoti_lakhani
 
PPSX
Ds04 abstract data types (adt) jyoti lakhani
jyoti_lakhani
 
PPSX
Ds03 part i algorithms by jyoti lakhani
jyoti_lakhani
 
PPSX
Ds03 algorithms jyoti lakhani
jyoti_lakhani
 
PPSX
Ds02 flow chart and pseudo code
jyoti_lakhani
 
PPSX
Ds01 data structure introduction - by jyoti lakhani
jyoti_lakhani
 
DOCX
Ids 016 cooperative intrusion detection
jyoti_lakhani
 
CG02 Computer Graphic Systems.ppsx
jyoti_lakhani
 
Projections.pptx
jyoti_lakhani
 
CG04 Color Models.ppsx
jyoti_lakhani
 
CG03 Random Raster Scan displays and Color CRTs.ppsx
jyoti_lakhani
 
CG02 Computer Graphic Systems.pptx
jyoti_lakhani
 
CG01 introduction.ppsx
jyoti_lakhani
 
Doubly linked list
jyoti_lakhani
 
Double ended queue
jyoti_lakhani
 
Priority queue
jyoti_lakhani
 
Ds006 linked list- delete from front
jyoti_lakhani
 
Ds06 linked list- insert a node after a given node
jyoti_lakhani
 
Ds06 linked list- insert a node at end
jyoti_lakhani
 
Ds06 linked list- insert a node at beginning
jyoti_lakhani
 
Ds06 linked list- intro and create a node
jyoti_lakhani
 
Ds04 abstract data types (adt) jyoti lakhani
jyoti_lakhani
 
Ds03 part i algorithms by jyoti lakhani
jyoti_lakhani
 
Ds03 algorithms jyoti lakhani
jyoti_lakhani
 
Ds02 flow chart and pseudo code
jyoti_lakhani
 
Ds01 data structure introduction - by jyoti lakhani
jyoti_lakhani
 
Ids 016 cooperative intrusion detection
jyoti_lakhani
 
Ad

Recently uploaded (20)

PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 

Tree terminology and introduction to binary tree

  • 1. TREES A Non Linear Data Structure in which data items have hierarchical relationship Definition: A tree can be theoretically defined as a finite set of one or more data items (or nodes) such that : 1. There is a special node called the root of the tree. 2. Other nodes are partitioned into number of mutually exclusive (i.e., disjoined) subsets each of which is itself a tree, are called sub tree. TREE Terminology Root A specially designed node in a tree It is the first node in the tree In above Fig. A is root node Node Each data item in a tree is called a node It specifies the data and links to other nodes A B C D E Root Root Leave Leave Computational Real Tree F G Parent Node Child Node
  • 2. A B C D E Root Leave Computational F G A B C D E Root Leave F G Level 0 Level 1 Level 2 Degree of a Node Number of sub-trees of a node Degree of A node = 2 Degree of B node = 3 Degree of C node = 1 Degree of D node = 0 Degree of E node = 0 Degree of F node = 0 Degree of G node = 0 Degree of a Tree The maximum degree of node in a tree. Eg. The degree of above tree is 3 All other nodes can have <= degree of nodes Means a node in this tree can have (0/ 1/2/3) no. of nodes Terminal Node (Leaf node) A node with degree 0 (no child) Eg. G, D, E, and F are leaf nodes Intermediate node A node with non-zero degree Eg. B and C nodes Levels in Tree A tree is structured in levels Point to Remember IF a node is at level n then its child will be at n+1 level Depth/ Height of a Tree Maximum level of any node in a given tree
  • 3. Eg. Height of tree = 2
  • 4. R B C D E Root F G T1 T2 A B C D E F G Binary A B C D E F G H J I K Binary Tree BINARY TREE Definition: A Binary Tree is a tree in which A node can have only(at most) 2 child nodes ( 0 child/ 1 child/ 2 childs) The two children are called ‘Left Child’ and ‘Right Child’ respectively. A binary tree T is defined as a finite set of elements, called nodes, such that- T is empty, if T has no nodes (called empty tree/ null tree) T contains a special node R, called Root node of T, and other nodes of T, form an ordered pair of disjoint binary trees T1 and T2. T1 and T2 are called Left and Right sub-trees of R. If T1 is non empty, then its root is called Left Successor(child) of R If T2 is non empty, then its root is called Right Successor(child) of R Above Trees are Binary Trees. Now consider the following definition- Strictly Binary Tree A binary tree is said to be strictly binary tree if, All of its non-leaf nodes in a binary tree has non empty left and right sub-tree.
  • 5. A B C D E F G Strictly Binary Tree A B C D E F G H J I K Binary Tree * + C B A Every node in the strictly binary tree can have either no children or two children. They are also called 2-tree or extended binary tree Point to Remember A strictly binary tree with n leaves always contains 2n– 1 nodes Application of Binary Tree (2-Tree) The main application of a 2-tree is to represent and compute any algebraic expression using binary operation. Consider following expression: E = (( a + b ) * c) E can be represented by using 2-Tree- This is called Expression Tree. .
  • 6. / X Y * - e d c / X Y + b a / + * b a - e d c A B C D E F G Complete Binary Tree How to create Expression Tree? Consider the given Expression- E = a + b/c – d *e 1. Put parenthesis in the expression (if missing) 2. Find the center of the expression E= (a + b) / ( (c – d ) *e ) X=(a + b) Y=( (c – d ) *e ) E= X/Y 3. Make the center operator as Root node 4. Now expand X and Y in Tree Complete Binary Tree A complete binary tree at depth ‘d’ is the strictly binary tree, where all the leaves are at level d.
  • 7. A B C D E F G Complete Binary Tree A B G Binary Tree A B C F E G D Complete Binary Tree I H K J M L O N Point to Remember A binary tree with n nodes, n > 0, has exactly n – 1 edges A binary tree of depth d, d > 0, has at least d and at most 2d – 1 nodes in it. If a binary tree contains n nodes at level L, then it can contains at most 2n nodes at level L + 1 A complete binary tree of depth d is the binary tree of depth d contains exactly 2 L nodes at each level L between 0 and d
  • 8. A B G Left Skewed Binary Tree A B G Right Skewed Binary Tree If a binary tree has only left sub trees, then it is called left skewed binary tree. If a binary tree has only right sub trees, then it is called right skewed binary tree.
  • 9. A B C E F G BINARY TREE REPRESENTATION There are two ways of representing binary tree T in memory : 1. Sequential representation using arrays 2. Linked list representation ARRAY REPRESENTATION 1. An array can be used to store the nodes of a binary tree. 2. The nodes stored in an array of memory can be accessed sequentially. 3. Suppose a binary tree T of depth d. Then at most 2d – 1 nodes can be there in T. 4. So an array of size 2d -1 is required to represent T. Eg. Consider above binary tree of depth 3. Then 2d -1 = 23 – 1 = 7. Then the array Tree[7] is declared to hold the nodes. Array representation of above tree is- 0 1 2 3 4 5 6 A B C G E F A B C G E F Children of A shaded A B C G E F Children of B shaded A B C G E F Children of C shaded
  • 10. Point to Remember 1. The parent of a node having index n can be obtained by the formula- Parent = (n – 1)/2 Parent = (index of child node – 1)/2 Eg. C is located at index 2 so n=2; parent of C is located at – (2-1)/2= ½ = 0.5 = 0 index; means it is A. Parent of E is located at (4-1)/2 = 3/2 = 1.5 = 1; means it is B. 2. The left child of a node having index n can be obtained by the formula- Left child = (2n+1) Left Child = (2 * Index of Parent) + 1 Eg. Left child of B is = 2*index of B +1 = (2*1)+1 = 2+1=3 3. The right child of a node having array index n can be obtained by the formula- Right child = (2n + 2) Right Child = (2 * index of parent) + 2 Eg. Right child of C is = (2*index of C) +2 = (2*2)+2 = 6 4. If the left child is at array index n, then its right sibling is at (n + 1). Right child = (n + 1) Right Child = ( index of left child + 1 ) 5. Similarly, if the right child is at index n, then its left sibling is at (n – 1)
  • 11. Left child = (n - 1) Left Child = ( index of right child - 1 )