SlideShare a Scribd company logo
1 of 24
Introduction to Binary Tree
Prepared by
Mrs. Swarupa Deshpande
Introduction
● A data structure is a way of organizing, storing, and managing
data so that it can be used efficiently.
● Data structures are an important part of several computer
algorithms and programs.
● They help programmers in designing efficient software.
● Data structures are used in all domains of computer science such
as Artificial Intelligence and Operating systems.
Tree node structure
● C Structure to represent a node of a Tree:
struct TreeNode {
int info;
TreeNode * left;
TreeNode * right;
};
Binary Tree
● Binary Tree is a special form of a tree
● A tree in which each branch node has the same out- degree
● Binary tree is important and frequently used in various applications of
computer science
Complete Tree
● A tree with n nodes and of depth k is complete iff its nodes correspond to the
nodes which are numbered one to n in the full tree of depth k
● A binary tree of height, h, is complete iff it is empty or
● its left subtree is complete of height h – 1 and its right subtree is completely
full f height h – 2 or – its left subtree is completely full of height h-1 and its
right subtree is complete of height h – 1
● A binary tree is completely full if it is of height, h and has (2h+1 – 1) nodes
Full Binary Tree
● A binary tree is a full binary tree, if it contains maximum possible number
of nodes in all levels
● In a full binary tree each node has two children or no child at all
● Total number of nodes in full binary tree of height h is 2h+1 – 1
considering root at level 0.
● It can be calculated as by adding number of nodes of each level 2 0 + 2 1 +
2 2 + ………..+ 2 h = 2 h+1 – 1
● Binary tree is a full binary tree, if it contains maximum possible
number of nodes in all levels
● In a full binary tree each node has two children or no child at all
● Total number of nodes in full binary tree of height h is 2h+1 –
1 considering root at level 0.
● It can be calculated as by adding number of nodes of each level 2
0 + 2 1 + 2 2 + ………..+ 2 h = 2 h+1 – 1
7
Trees 1/7/2021
Full Binary Tree
● A binary tree is said to be a complete binary tree, if all its level,
except the last level, have maximum number of possible nodes, and
all the nodes of the last level appear as far left as possible
● In a complete binary tree all leaf nodes are at last and second last
level and levels are filled from left to right
Complete Binary Tree
Complete Binary Tree
8
Trees 1/7/2021
● Every non-terminal node in a binary tree consists of non- empty
left subtree & right subtree, then such a tree is called Strictly
Binary Tree
Strictly Binary Tree
9
Trees 1/7/2021
● A binary tree T consists of each node has 0 or 2 children is called
extended binary tree
● Node with 2 children are called internal nodes and nodes with 0
children are called external nodes
● Trees can be converted into extended trees by adding a node
10
Trees 1/7/2021
Binary Tree
❖ Definition : A Binary Tree is either :
an empty tree; or
It consists of a node, called root and two children, left
and right, each of which are themselves binary trees
Binary Tree
11
Trees 1/7/2021
12
A null tree is
a tree with
no nodes
Some Properties of Binary Trees
● The height of binary trees can be mathematically predicted
● Given that we need to store N nodes in a binary tree, the maximum height
is
13
A tree with a maximum height is rare. It occurs when all of the nodes in the entire
tree have only one successor.
Some Properties of Binary Trees
● The minimum height of a binary tree is determined as follows:
14
For instance, if there are three nodes to be stored in the binary tree (N=3) then
Hmin
=2.
Some Properties of Binary Trees
● Given a height of the binary tree, H, the minimum number of nodes in
the tree is given as follows:
15
Some Properties of Binary Trees
● The formula for the maximum number of nodes is derived from the
fact that each node can have only two descendents. Given a height of
the binary tree, H, the maximum number of nodes in the tree is given
as follows:
16
Some Properties of Binary Trees
● The children of any node in a tree can be accessed by following only one
branch path, the one that leads to the desired node.
● The nodes at level 1, which are children of the root, can be accessed by
following only one branch; the nodes of level 2 of a tree can be accessed by
following only two branches from the root, etc.
● The balance factor of a binary tree is the difference in height between its left
and right subtrees:
17
18
B=0 B=0 B=1 B=-1
B=0 B=1
B=-2 B=2
Balance of the tree
Binary trees are trees where the maximum degree of any node is two
1/7/2021
● Any general tree can be represented as a binary tree
using the ALL nodes general tree will be nodes of binary tree.
● The root of the Binary Tree is the Root of the Generic Tree.
● The left child of a node in the Generic Tree is the Left child of that
node in the Binary Tree.
● The right sibling of any node in the Generic Tree is the Right child
of that node in the Binary Tree.
Conversion Of A General Tree To Binary Tree
Binary trees are trees where the maximum degree of any node is two
1/7/2021
Conversion Of A General Tree To Binary Tree
Binary trees are trees where the maximum degree of any node is two
1/7/2021
Conversion Of A General Tree To Binary Tree
Below are the steps for the conversion of Generic Tree to Binary Tree:
1. As per the rules mentioned above, the root node of general tree A is the root
node of the binary tree.
2. Now the leftmost child node of the root node in the general tree is B and it is
the leftmost child node of the binary tree.
3. Now as B has E as its leftmost child node, so it is its leftmost child node in
the binary tree whereas it has C as its rightmost sibling node so it is its right
child node in the binary tree.
4. Now C has F as its leftmost child node and D as its rightmost sibling node,
so they are its left and right child node in the binary tree respectively.
Binary trees are trees where the maximum degree of any node is two
1/7/2021
Conversion Of A General Tree To Binary Tree
5. Now D has I as its leftmost child node which is its left child node in the binary tree
but doesn’t have any rightmost sibling node, so doesn’t have any right child in the
binary tree.
6. Now for I, J is its rightmost sibling node and so it is its right child node in the
binary tree.
7. Similarly, for J, K is its leftmost child node and thus it is its left child node in the
binary tree.
8. Now for C, F is its leftmost child node, which has G as its rightmost sibling node,
which has H as its just right sibling node and thus they form their left, right, and right
child node respectively.
Binary trees are trees where the maximum degree of any node is two
1/7/2021
Conversion of A General Tree To Binary Tree
Trees 1/7/2021
Example

More Related Content

Similar to Introduction to Binary Tree and Conersion of General tree to Binary Tree

358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10sumitbardhan
 
Binary Tree in Data Structures-Unit 2.pptx
Binary Tree in Data Structures-Unit 2.pptxBinary Tree in Data Structures-Unit 2.pptx
Binary Tree in Data Structures-Unit 2.pptxUsriDevi1
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationnakulvarshney371
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptxAbirami A
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxRajitha Reddy Alugati
 
Lecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptxLecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptxfizzaahmed9
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2smruti sarangi
 
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
TERMINOLOGIES OF TREE, TYPES OF TREE.pptxTERMINOLOGIES OF TREE, TYPES OF TREE.pptx
TERMINOLOGIES OF TREE, TYPES OF TREE.pptxKALPANAC20
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsBHARATH KUMAR
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxLecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxHamzaUsman48
 
Tree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data StructureTree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data StructureManoj PAtil
 

Similar to Introduction to Binary Tree and Conersion of General tree to Binary Tree (20)

Binary tree
Binary treeBinary tree
Binary tree
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Binary Tree in Data Structures-Unit 2.pptx
Binary Tree in Data Structures-Unit 2.pptxBinary Tree in Data Structures-Unit 2.pptx
Binary Tree in Data Structures-Unit 2.pptx
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentation
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
heap sort
 heap sort heap sort
heap sort
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
 
Lecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptxLecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptx
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
 
AD3251-Data Structures Design-Notes-Tree.pdf
AD3251-Data Structures  Design-Notes-Tree.pdfAD3251-Data Structures  Design-Notes-Tree.pdf
AD3251-Data Structures Design-Notes-Tree.pdf
 
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
TERMINOLOGIES OF TREE, TYPES OF TREE.pptxTERMINOLOGIES OF TREE, TYPES OF TREE.pptx
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and Algorithms
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxLecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
Tree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data StructureTree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data Structure
 

Recently uploaded

Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 

Recently uploaded (20)

Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 

Introduction to Binary Tree and Conersion of General tree to Binary Tree

  • 1. Introduction to Binary Tree Prepared by Mrs. Swarupa Deshpande
  • 2. Introduction ● A data structure is a way of organizing, storing, and managing data so that it can be used efficiently. ● Data structures are an important part of several computer algorithms and programs. ● They help programmers in designing efficient software. ● Data structures are used in all domains of computer science such as Artificial Intelligence and Operating systems.
  • 3. Tree node structure ● C Structure to represent a node of a Tree: struct TreeNode { int info; TreeNode * left; TreeNode * right; };
  • 4. Binary Tree ● Binary Tree is a special form of a tree ● A tree in which each branch node has the same out- degree ● Binary tree is important and frequently used in various applications of computer science
  • 5. Complete Tree ● A tree with n nodes and of depth k is complete iff its nodes correspond to the nodes which are numbered one to n in the full tree of depth k ● A binary tree of height, h, is complete iff it is empty or ● its left subtree is complete of height h – 1 and its right subtree is completely full f height h – 2 or – its left subtree is completely full of height h-1 and its right subtree is complete of height h – 1 ● A binary tree is completely full if it is of height, h and has (2h+1 – 1) nodes
  • 6. Full Binary Tree ● A binary tree is a full binary tree, if it contains maximum possible number of nodes in all levels ● In a full binary tree each node has two children or no child at all ● Total number of nodes in full binary tree of height h is 2h+1 – 1 considering root at level 0. ● It can be calculated as by adding number of nodes of each level 2 0 + 2 1 + 2 2 + ………..+ 2 h = 2 h+1 – 1
  • 7. ● Binary tree is a full binary tree, if it contains maximum possible number of nodes in all levels ● In a full binary tree each node has two children or no child at all ● Total number of nodes in full binary tree of height h is 2h+1 – 1 considering root at level 0. ● It can be calculated as by adding number of nodes of each level 2 0 + 2 1 + 2 2 + ………..+ 2 h = 2 h+1 – 1 7 Trees 1/7/2021 Full Binary Tree
  • 8. ● A binary tree is said to be a complete binary tree, if all its level, except the last level, have maximum number of possible nodes, and all the nodes of the last level appear as far left as possible ● In a complete binary tree all leaf nodes are at last and second last level and levels are filled from left to right Complete Binary Tree Complete Binary Tree 8 Trees 1/7/2021
  • 9. ● Every non-terminal node in a binary tree consists of non- empty left subtree & right subtree, then such a tree is called Strictly Binary Tree Strictly Binary Tree 9 Trees 1/7/2021
  • 10. ● A binary tree T consists of each node has 0 or 2 children is called extended binary tree ● Node with 2 children are called internal nodes and nodes with 0 children are called external nodes ● Trees can be converted into extended trees by adding a node 10 Trees 1/7/2021 Binary Tree
  • 11. ❖ Definition : A Binary Tree is either : an empty tree; or It consists of a node, called root and two children, left and right, each of which are themselves binary trees Binary Tree 11 Trees 1/7/2021
  • 12. 12 A null tree is a tree with no nodes
  • 13. Some Properties of Binary Trees ● The height of binary trees can be mathematically predicted ● Given that we need to store N nodes in a binary tree, the maximum height is 13 A tree with a maximum height is rare. It occurs when all of the nodes in the entire tree have only one successor.
  • 14. Some Properties of Binary Trees ● The minimum height of a binary tree is determined as follows: 14 For instance, if there are three nodes to be stored in the binary tree (N=3) then Hmin =2.
  • 15. Some Properties of Binary Trees ● Given a height of the binary tree, H, the minimum number of nodes in the tree is given as follows: 15
  • 16. Some Properties of Binary Trees ● The formula for the maximum number of nodes is derived from the fact that each node can have only two descendents. Given a height of the binary tree, H, the maximum number of nodes in the tree is given as follows: 16
  • 17. Some Properties of Binary Trees ● The children of any node in a tree can be accessed by following only one branch path, the one that leads to the desired node. ● The nodes at level 1, which are children of the root, can be accessed by following only one branch; the nodes of level 2 of a tree can be accessed by following only two branches from the root, etc. ● The balance factor of a binary tree is the difference in height between its left and right subtrees: 17
  • 18. 18 B=0 B=0 B=1 B=-1 B=0 B=1 B=-2 B=2 Balance of the tree
  • 19. Binary trees are trees where the maximum degree of any node is two 1/7/2021 ● Any general tree can be represented as a binary tree using the ALL nodes general tree will be nodes of binary tree. ● The root of the Binary Tree is the Root of the Generic Tree. ● The left child of a node in the Generic Tree is the Left child of that node in the Binary Tree. ● The right sibling of any node in the Generic Tree is the Right child of that node in the Binary Tree. Conversion Of A General Tree To Binary Tree
  • 20. Binary trees are trees where the maximum degree of any node is two 1/7/2021 Conversion Of A General Tree To Binary Tree
  • 21. Binary trees are trees where the maximum degree of any node is two 1/7/2021 Conversion Of A General Tree To Binary Tree Below are the steps for the conversion of Generic Tree to Binary Tree: 1. As per the rules mentioned above, the root node of general tree A is the root node of the binary tree. 2. Now the leftmost child node of the root node in the general tree is B and it is the leftmost child node of the binary tree. 3. Now as B has E as its leftmost child node, so it is its leftmost child node in the binary tree whereas it has C as its rightmost sibling node so it is its right child node in the binary tree. 4. Now C has F as its leftmost child node and D as its rightmost sibling node, so they are its left and right child node in the binary tree respectively.
  • 22. Binary trees are trees where the maximum degree of any node is two 1/7/2021 Conversion Of A General Tree To Binary Tree 5. Now D has I as its leftmost child node which is its left child node in the binary tree but doesn’t have any rightmost sibling node, so doesn’t have any right child in the binary tree. 6. Now for I, J is its rightmost sibling node and so it is its right child node in the binary tree. 7. Similarly, for J, K is its leftmost child node and thus it is its left child node in the binary tree. 8. Now for C, F is its leftmost child node, which has G as its rightmost sibling node, which has H as its just right sibling node and thus they form their left, right, and right child node respectively.
  • 23. Binary trees are trees where the maximum degree of any node is two 1/7/2021 Conversion of A General Tree To Binary Tree