SlideShare a Scribd company logo
1 of 12
M–ary Tree
Presented By:
Md. Arif Hasan – BSSE1112
Tahmeed Mahbub – BSSE1127
Tasmia Zerin – BSSE1128
Balanced
Tree
B
Tree
General
Tree
M – ary
Tree
Where is M-ary
tree in the tree of
TREEs ?
AVL
Tree
Red/
Black
Tree
B+
Tree
Here I am!
Binary
Tree
1.
What is M-ary Tree?
A rooted tree is called an m-ary tree if every internal vertex has no more then m
children.
Types of m-ary tree:
• A full m-ary tree is an m-ary tree where within each level
every node has either 0 or m children.
• A complete m-ary tree is an m-ary tree which must be
completely filled on every level except for the last level.
However, if the last level is not complete, then all nodes
of the tree must be as far left as possible.
• A perfect m-ary tree is a full m-ary tree in which all leaf
nodes are at the same depth.
1 2 3 m
Internal Vertices
2.
Properties of m-ary tree:
• A full m-ary tree with i internal vertices contains n= mi + 1
vertices and l=(m-1)i+1 leaves
i = 4 internal vertices
m = 3
n = 3 x 4 + 1 = 13 vertices, as 12
vertices (except the root) are children of
those 4 internal vertices
So, children = m x i = 4 x 3 = n – 1
n = l + i => l = (m-1)i + 1
l = 2 x 4 + 1 = 9 leaves
Internal Vertices
3.
The children of m-ary tree:
Binary
Tree
M – ary
Tree
Ternar
y Tree
M = 2 M = 3
Yes, I’m the parent of all 1,2,3……
ary trees
4.
Traversal Methods for m-ary tree:
Traversing a m-ary tree is very similar to binary tree traversal. But since there are
more than two children per node for m > 2, one must define the notion
of left and right subtrees. One common method to establish left/right subtrees is
to divide the list of children nodes into two groups.By defining an order on the
m children of a node, the first {0,1,…. └m/2┘} nodes would constitute the left
subtree and {
┌m/2
┐,…..,m} would constitute the right subtree.
5.
Left Subtree Right Subtree
Here, for m = 3,
left subtree will
be { 0, 1 } (as 3/2 =
1) and right
subtree will be { 2
}
For Example:
6.
Methods of Storing m-ary trees:
• Arrays: if the tree is a
complete m-ary tree, this
method wastes no space. In
this compact arrangement, if
a node has an index i, its c-
th child in range {1,...,m} is
found at index m.i + c. The
space complexity of this
method is O ( mn )
A
B
C
D
E
F
G
A
D
C
B
E G
F
0
1 2 3
4 5 6 7 8 9 10 11 12
0
1
2
3
4
5
6
7
8
9
10
11
12
7.
• Pointer Based: Each node
would have an internal array
for storing pointers to each of
its m children. Compared to
array-based implementation,
this implementation method
has superior space complexity
of O (m.n)
8.
Convert a m-ary tree to binary tree:
Converting an arbitrary m-ary tree to a binary tree would only increase the height of
the tree by a constant factor and would not affect the overall worst-case time
complexity. First, we link all the immediate children nodes of a given parent node
together in order to form a link list. Then, we keep the link from the parent to the
first (i.e., the leftmost) child and remove all the other links to the rest of the children.
We repeat this process for all the children (if they have any children) until we have
processed all the internal nodes and rotate the tree by 45 degrees clockwise. The tree
obtained is the desired binary tree obtained from the given m-ary tree.
9.
A
G
E
B C
J
I
F
K
D
H
O
N
L M
P Q
G
B C F
D E
A
J
I
H K L
P Q
M
O
N
G
B
C
F
E
A
J
P
O
O
N
A
C
J
I
F
K
D
H
O
N
M
P
E
L
G
B
Q
Converting m-ary to binary tree
10.
Thank You

More Related Content

What's hot (20)

Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Karnaugh map
Karnaugh mapKarnaugh map
Karnaugh map
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Threaded binary tree
Threaded binary treeThreaded binary tree
Threaded binary tree
 
SOP POS, Minterm and Maxterm
SOP POS, Minterm and MaxtermSOP POS, Minterm and Maxterm
SOP POS, Minterm and Maxterm
 
Isomorphic graph
Isomorphic graphIsomorphic graph
Isomorphic graph
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
Tree
TreeTree
Tree
 
Weighted and Non Weighted Codes
Weighted and Non Weighted CodesWeighted and Non Weighted Codes
Weighted and Non Weighted Codes
 
Sum of subset problem.pptx
Sum of subset problem.pptxSum of subset problem.pptx
Sum of subset problem.pptx
 
Trees - Non Linear Data Structure
Trees - Non Linear Data StructureTrees - Non Linear Data Structure
Trees - Non Linear Data Structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbers
 

Similar to M ary-tree

Similar to M ary-tree (20)

Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics Tree
 
Tree in discrete structure
Tree in discrete structureTree in discrete structure
Tree in discrete structure
 
B.TECH Math project
B.TECH Math projectB.TECH Math project
B.TECH Math project
 
Binary tree
Binary treeBinary tree
Binary tree
 
B tree-180214044656
B tree-180214044656B tree-180214044656
B tree-180214044656
 
B tree
B  treeB  tree
B tree
 
Unit III - NON LINEAR DATA STRUCTURES
Unit III -  NON LINEAR DATA STRUCTURESUnit III -  NON LINEAR DATA STRUCTURES
Unit III - NON LINEAR DATA STRUCTURES
 
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binary
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
08 B Trees
08 B Trees08 B Trees
08 B Trees
 
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
 
trees-and-forest.pdf
trees-and-forest.pdftrees-and-forest.pdf
trees-and-forest.pdf
 
DSA IV Unit.pptx
DSA IV Unit.pptxDSA IV Unit.pptx
DSA IV Unit.pptx
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
Unit 3,4.docx
Unit 3,4.docxUnit 3,4.docx
Unit 3,4.docx
 
trees.ppt
trees.ppttrees.ppt
trees.ppt
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Trees ayaz
Trees ayazTrees ayaz
Trees ayaz
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 

Recently uploaded

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Recently uploaded (20)

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

M ary-tree

  • 1. M–ary Tree Presented By: Md. Arif Hasan – BSSE1112 Tahmeed Mahbub – BSSE1127 Tasmia Zerin – BSSE1128
  • 2. Balanced Tree B Tree General Tree M – ary Tree Where is M-ary tree in the tree of TREEs ? AVL Tree Red/ Black Tree B+ Tree Here I am! Binary Tree 1.
  • 3. What is M-ary Tree? A rooted tree is called an m-ary tree if every internal vertex has no more then m children. Types of m-ary tree: • A full m-ary tree is an m-ary tree where within each level every node has either 0 or m children. • A complete m-ary tree is an m-ary tree which must be completely filled on every level except for the last level. However, if the last level is not complete, then all nodes of the tree must be as far left as possible. • A perfect m-ary tree is a full m-ary tree in which all leaf nodes are at the same depth. 1 2 3 m Internal Vertices 2.
  • 4. Properties of m-ary tree: • A full m-ary tree with i internal vertices contains n= mi + 1 vertices and l=(m-1)i+1 leaves i = 4 internal vertices m = 3 n = 3 x 4 + 1 = 13 vertices, as 12 vertices (except the root) are children of those 4 internal vertices So, children = m x i = 4 x 3 = n – 1 n = l + i => l = (m-1)i + 1 l = 2 x 4 + 1 = 9 leaves Internal Vertices 3.
  • 5. The children of m-ary tree: Binary Tree M – ary Tree Ternar y Tree M = 2 M = 3 Yes, I’m the parent of all 1,2,3…… ary trees 4.
  • 6. Traversal Methods for m-ary tree: Traversing a m-ary tree is very similar to binary tree traversal. But since there are more than two children per node for m > 2, one must define the notion of left and right subtrees. One common method to establish left/right subtrees is to divide the list of children nodes into two groups.By defining an order on the m children of a node, the first {0,1,…. └m/2┘} nodes would constitute the left subtree and { ┌m/2 ┐,…..,m} would constitute the right subtree. 5.
  • 7. Left Subtree Right Subtree Here, for m = 3, left subtree will be { 0, 1 } (as 3/2 = 1) and right subtree will be { 2 } For Example: 6.
  • 8. Methods of Storing m-ary trees: • Arrays: if the tree is a complete m-ary tree, this method wastes no space. In this compact arrangement, if a node has an index i, its c- th child in range {1,...,m} is found at index m.i + c. The space complexity of this method is O ( mn ) A B C D E F G A D C B E G F 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 7.
  • 9. • Pointer Based: Each node would have an internal array for storing pointers to each of its m children. Compared to array-based implementation, this implementation method has superior space complexity of O (m.n) 8.
  • 10. Convert a m-ary tree to binary tree: Converting an arbitrary m-ary tree to a binary tree would only increase the height of the tree by a constant factor and would not affect the overall worst-case time complexity. First, we link all the immediate children nodes of a given parent node together in order to form a link list. Then, we keep the link from the parent to the first (i.e., the leftmost) child and remove all the other links to the rest of the children. We repeat this process for all the children (if they have any children) until we have processed all the internal nodes and rotate the tree by 45 degrees clockwise. The tree obtained is the desired binary tree obtained from the given m-ary tree. 9.
  • 11. A G E B C J I F K D H O N L M P Q G B C F D E A J I H K L P Q M O N G B C F E A J P O O N A C J I F K D H O N M P E L G B Q Converting m-ary to binary tree 10.