SlideShare a Scribd company logo
1 of 8
BINARY TREE
1
A SEMINAR ON BY=Mubeen Momin Abdul
Qadeer (co-3g)
Roll no = 5
Binary Trees
• According to the definition of trees, a node can
have any number of children.
• A binary tree is restricted to only having 0, 1, or 2
children.
• A complete binary tree is one where all the levels
are full with exception to the last level and it is
filled from left to right.
• A full binary tree is one where if a node has a
child, then it has two children.
BINARY TREES
Every node in a binary tree can
have at most two children.
The two children of each node are
called the left child and right child
corresponding to their positions.
A node can have only a left child or
only a right child or it can have no
children at all.
Left child is always less that its
parent, while right child is greater
than its parent.
TERMINOLOGY
Each node has to be reachable from the
roots through a unique sequence of arcs
called a path.
The number of arcs in a path is called the
length of the path.
The level of a node is the length of the
path from the root to the node plus 1.
The height of a non-empty tree is the
maximum level of a node in the tree.
Picture of a binary tree5
a
b c
d e
g h i
l
f
j k
The root is
drawn at the top
Tree traversals
 A binary tree is defined recursively: it consists of a root, a
left subtree, and a right subtree
 To traverse (or walk) the binary tree is to visit each node
in the binary tree exactly once
 Tree traversals are naturally recursive
 Since a binary tree has three “parts,” there are six
possible ways to traverse the binary tree:
 root, left, right
 left, root, right
 left, right, root
 root, right, left
 right, root, left
 right, left, root
6
Tree Traversals using
“flags”
• The order in which the nodes are visited during a tree
traversal can be easily determined by imagining there is a
“flag” attached to each node, as follows
• To traverse the tree, collect the flags
7
preorder inorder postorder
A
B C
D E F G
A
B C
D E F G
A
B C
D E F G
A B D E C F G D B E A F C G D E B F G C A
SORTED BINARY
TREES
A binary tree is sorted if every node in the tree is larger
than (or equal to) its left descendants, and smaller than
(or equal to) its right descendants
Equal nodes can go either on the left or the right (but it
has to be consistent)
8
10
8 15
4 12 20
17

More Related Content

Similar to BINARY TREE

Similar to BINARY TREE (16)

Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
 
Binary tree
Binary treeBinary tree
Binary tree
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
Tree
TreeTree
Tree
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Unit 3 dsuc
Unit 3 dsucUnit 3 dsuc
Unit 3 dsuc
 
Trees krw
Trees krwTrees krw
Trees krw
 
Binary tree
Binary treeBinary tree
Binary tree
 
Trees
TreesTrees
Trees
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basics
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
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
 
Trees
TreesTrees
Trees
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Red black trees
Red black treesRed black trees
Red black trees
 
tree in Data Structures
tree in Data Structurestree in Data Structures
tree in Data Structures
 

More from mubeenm50 (7)

Hacking version 2
Hacking version 2Hacking version 2
Hacking version 2
 
Listening skills
Listening skills Listening skills
Listening skills
 
(CGI) Computer generated imagery ppt by Mubeen Momin
(CGI) Computer generated imagery ppt by Mubeen Momin(CGI) Computer generated imagery ppt by Mubeen Momin
(CGI) Computer generated imagery ppt by Mubeen Momin
 
Hacking
HackingHacking
Hacking
 
Virtual reality with head movement tracking by mubeen momin
Virtual reality with head movement tracking by mubeen mominVirtual reality with head movement tracking by mubeen momin
Virtual reality with head movement tracking by mubeen momin
 
Jini java protocol ppt by Mubeen
Jini java protocol  ppt by MubeenJini java protocol  ppt by Mubeen
Jini java protocol ppt by Mubeen
 
Wi fi ppt project by Mubeen Momin
Wi fi ppt project by Mubeen MominWi fi ppt project by Mubeen Momin
Wi fi ppt project by Mubeen Momin
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

BINARY TREE

  • 1. BINARY TREE 1 A SEMINAR ON BY=Mubeen Momin Abdul Qadeer (co-3g) Roll no = 5
  • 2. Binary Trees • According to the definition of trees, a node can have any number of children. • A binary tree is restricted to only having 0, 1, or 2 children. • A complete binary tree is one where all the levels are full with exception to the last level and it is filled from left to right. • A full binary tree is one where if a node has a child, then it has two children.
  • 3. BINARY TREES Every node in a binary tree can have at most two children. The two children of each node are called the left child and right child corresponding to their positions. A node can have only a left child or only a right child or it can have no children at all. Left child is always less that its parent, while right child is greater than its parent.
  • 4. TERMINOLOGY Each node has to be reachable from the roots through a unique sequence of arcs called a path. The number of arcs in a path is called the length of the path. The level of a node is the length of the path from the root to the node plus 1. The height of a non-empty tree is the maximum level of a node in the tree.
  • 5. Picture of a binary tree5 a b c d e g h i l f j k The root is drawn at the top
  • 6. Tree traversals  A binary tree is defined recursively: it consists of a root, a left subtree, and a right subtree  To traverse (or walk) the binary tree is to visit each node in the binary tree exactly once  Tree traversals are naturally recursive  Since a binary tree has three “parts,” there are six possible ways to traverse the binary tree:  root, left, right  left, root, right  left, right, root  root, right, left  right, root, left  right, left, root 6
  • 7. Tree Traversals using “flags” • The order in which the nodes are visited during a tree traversal can be easily determined by imagining there is a “flag” attached to each node, as follows • To traverse the tree, collect the flags 7 preorder inorder postorder A B C D E F G A B C D E F G A B C D E F G A B D E C F G D B E A F C G D E B F G C A
  • 8. SORTED BINARY TREES A binary tree is sorted if every node in the tree is larger than (or equal to) its left descendants, and smaller than (or equal to) its right descendants Equal nodes can go either on the left or the right (but it has to be consistent) 8 10 8 15 4 12 20 17