SlideShare a Scribd company logo
19
Most read
21
Most read
24
Most read
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

PPT
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
PPTX
Recovery techniques
PPTX
Binary Tree Traversal
PPTX
PPTX
Quick sort
PPT
b-tree.ppt
PPT
Doubly linked list
PPTX
Database Security And Authentication
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Recovery techniques
Binary Tree Traversal
Quick sort
b-tree.ppt
Doubly linked list
Database Security And Authentication

What's hot (20)

PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
PPTX
Tree Traversal
PDF
Deterministic Finite Automata (DFA)
PPTX
Binary Tree in Data Structure
PPTX
Discrete Mathematics Tree
PDF
Divide and Conquer
PDF
Árboles AA
PPTX
sorting and searching.pptx
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
Unit 1 polynomial manipulation
PPT
Trees
PPTX
Queues in C++
PPTX
Presentation on Relational Schema (Database)
PPT
Heaps & priority queues
PPTX
Unit 5 internal sorting & files
PPT
Greedy Algorithms Huffman Coding.ppt
PPTX
Moore Mealy Machine Conversion
PDF
Graph Theory: Trees
PDF
Binary codes
Trees, Binary Search Tree, AVL Tree in Data Structures
Tree Traversal
Deterministic Finite Automata (DFA)
Binary Tree in Data Structure
Discrete Mathematics Tree
Divide and Conquer
Árboles AA
sorting and searching.pptx
BINARY TREE REPRESENTATION.ppt
Unit 1 polynomial manipulation
Trees
Queues in C++
Presentation on Relational Schema (Database)
Heaps & priority queues
Unit 5 internal sorting & files
Greedy Algorithms Huffman Coding.ppt
Moore Mealy Machine Conversion
Graph Theory: Trees
Binary codes
Ad

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

PPT
Binary tree
PPTX
Tree all information about tree concept are available .
PPTX
Lecture 9: Binary tree basics
PPTX
Data Structure of computer science and technology
PDF
07 trees
PDF
Module - 5_Trees.pdf
PDF
unit-2-dsa-tree-2024-1 (1) (1).pdf data structure
PPT
358 33 powerpoint-slides_10-trees_chapter-10
PDF
PPTX
Lecture 21_Trees - I.pptx
PDF
unit-2-dsa-tree introduction of tree and terninology
PPT
Final tree.ppt tells about tree presentation
PPTX
Trees in Data Structure
PPTX
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
PPTX
non linear data structure -introduction of tree
PPTX
Binary Trees.pptx module 122img 787554yau
PPTX
NON-LINEAR DATA STRUCTURE-TREES.pptx
PPT
Introduction To Binary Search Trees .ppt
Binary tree
Tree all information about tree concept are available .
Lecture 9: Binary tree basics
Data Structure of computer science and technology
07 trees
Module - 5_Trees.pdf
unit-2-dsa-tree-2024-1 (1) (1).pdf data structure
358 33 powerpoint-slides_10-trees_chapter-10
Lecture 21_Trees - I.pptx
unit-2-dsa-tree introduction of tree and terninology
Final tree.ppt tells about tree presentation
Trees in Data Structure
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
non linear data structure -introduction of tree
Binary Trees.pptx module 122img 787554yau
NON-LINEAR DATA STRUCTURE-TREES.pptx
Introduction To Binary Search Trees .ppt
Ad

Recently uploaded (20)

PPT
Mechanical Engineering MATERIALS Selection
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Sustainable Sites - Green Building Construction
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT 4 Total Quality Management .pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Digital Logic Computer Design lecture notes
Mechanical Engineering MATERIALS Selection
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Sustainable Sites - Green Building Construction
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
CH1 Production IntroductoryConcepts.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT 4 Total Quality Management .pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Operating System & Kernel Study Guide-1 - converted.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
bas. eng. economics group 4 presentation 1.pptx
Geodesy 1.pptx...............................................
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
R24 SURVEYING LAB MANUAL for civil enggi
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Digital Logic Computer Design lecture notes

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