SlideShare a Scribd company logo
1 of 27
Introduction to Tree
• Fundamental data storage structures used
in programming.
• Combines advantages of an ordered array
and a linked list.
• Searching as fast as in ordered array.
• Insertion and deletion as fast as in linked
list.
Tree (example)
node
Draw a parse tree
Tree characteristics
• Consists of nodes connected by edges.
• Nodes often represent entities (complex
objects) such as people, car parts etc.
• Edges between the nodes represent the
way the nodes are related.
• Its easy for a program to get from one
node to another if there is a line
connecting them.
• The only way to get from node to node is
to follow a path along the edges.
Tree Terminology
• Path: Traversal from node to node along the edges
results in a sequence called path.
• Root: Node at the top of the tree.
• Parent: Any node, except root has exactly one edge
running upward to another node. The node above it is
called parent.
• Child: Any node may have one or more lines running
downward to other nodes. Nodes below are children.
• Leaf: A node that has no children.
• Subtree: Any node can be considered to be the root of a
subtree, which consists of its children and its children’s
children and so on.
Tree Terminology
• Visiting: A node is visited when program control
arrives at the node, usually for processing.
• Traversing: To traverse a tree means to visit all
the nodes in some specified order.
• Levels: The level of a particular node refers to
how many generations the node is from the root.
Root is assumed to be level 0.
• Keys: Key value is used to search for the item or
perform other operations on it.
Leaf
• A vertex is called a leaf if it has no
children.
6
7
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper
Joyce Chris Max Len
Leaf nodes have no children
LEAF NODES
8
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper
Joyce Chris Max Len
A Subtree
LEFT SUBTREE OF ROOT
ROOT
9
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper
Joyce Chris Max Len
Another Subtree
RIGHT SUBTREE OF ROOT
ROOT
m-ary trees
A rooted tree is called an m-ary tree if
every internal vertex has no more than m
children. The tree is called a full m-ary
tree if every internal vertex has exactly
m children. An m-ary tree with m=2 is
called a binary tree.
Ordered Rooted Tree
An ordered rooted tree is a rooted tree
where the children of each internal vertex
are ordered. Ordered trees are drawn so
that the children of each internal vertex
are shown in order from left to right.
Properties of Trees
A tree with n vertices has n-1 edges.
Properties of Trees
A full m-ary tree with i internal vertices
contains n = mi+1 vertices.
Properties of Trees
A full m-ary tree with
(i) n vertices has i = (n-1)/m internal
vertices and l = [(m-1)n+1]/m leaves.
(ii) i internal vertices has n = mi + 1
vertices and l = (m-1)i + 1 leaves.
(iii) l leaves has n = (ml - 1)/(m-1) vertices
and i = (l-1)/(m-1) internal vertices.
Proof
• We know n = mi+1 (previous theorem) and
n = l+i,
• n – no. vertices
• i – no. internal vertices
• l – no. leaves
• For example, i = (n-1)/m
Properties of Trees
The level of a vertex v in a rooted tree is
the length of the unique path from the root
to this vertex.
level 2
level 3
Properties of Trees
The height of a rooted tree is the maximum
of the levels of vertices.
Properties of Trees
A rooted m-ary tree of height h is called
balanced if all leaves are at levels h or h-1.
Properties of Trees
There are at most mh leaves in an m-ary
tree of height h.
Properties of Trees
If an m-ary tree of height h has l leaves,
then  h lm log
Proof
• From previous theorem:
  hlhlml mm
h
 loglog
Minimum Spanning Tree
• Input: A connected, undirected graph G =
(V, E) with weight function w : E  R.
• For simplicity, we assume that all edge
weights are distinct.
• Output: A spanning tree T, a tree that
connects all vertices, of minimum weight:



Tvu
vuwTw
),(
),()(
Example of MST
6 12
5
14
3
8
10
15
9
7
Kruskal’s Algorithm
It is a greedy algorithm.
 In Kruskal’s algorithm, the set A is a forest.
 The safe edge is added to A is always a
 least-weight edge in the graph that connects two
distinct Components.
Kruskal’s Algorithm
 The operation FIND-SET(u) returns a representative element
from the set that contains u.
 Thus we can determine whether two vertices u and v belong
the same tree by testing whether
FIND-SET(u) = FIND-SET(v)
 The combining of trees is accomplished by the
UNION procedure
Kruskal’s Algorithm
1. A  
2. for each vertex v  V[G]
3.do MAKE-SET(v)
4.short the edges of E into non-decreasing order
by weight.
5.for each edge (u, v)  E, taken in non-decreasing or
by weight.
6.do if FIND-SET(u) != FIND-SET(v)
7. then, A  A U {(u, v)}
8. UNION(u, v)
9.return A

More Related Content

What's hot (20)

Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Graphs - Discrete Math
Graphs - Discrete MathGraphs - Discrete Math
Graphs - Discrete Math
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm Presentation
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
single linked list
single linked listsingle linked list
single linked list
 
Tree
TreeTree
Tree
 
1.8 splay tree
1.8 splay tree 1.8 splay tree
1.8 splay tree
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Tree-In Data Structure
Tree-In Data StructureTree-In Data Structure
Tree-In Data Structure
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 

Viewers also liked

Trees (slides)
Trees (slides)Trees (slides)
Trees (slides)IIUM
 
Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 
Tree in Discrete structure
Tree in Discrete structureTree in Discrete structure
Tree in Discrete structureNoman Rajput
 
Relations digraphs
Relations  digraphsRelations  digraphs
Relations digraphsIIUM
 
Discrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIDiscrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIWongyos Keardsri
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Treecinterviews
 
Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Fahrul Usman
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphsmaznabili
 
Lattices AND Hasse Diagrams
Lattices AND Hasse DiagramsLattices AND Hasse Diagrams
Lattices AND Hasse DiagramsDebarati Das
 
1.4 expression tree
1.4 expression tree  1.4 expression tree
1.4 expression tree Krish_ver2
 
Discrete math ppt
Discrete math pptDiscrete math ppt
Discrete math pptmsumerton
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
Discrete-Chapter 05 Inference and Proofs
Discrete-Chapter 05 Inference and ProofsDiscrete-Chapter 05 Inference and Proofs
Discrete-Chapter 05 Inference and ProofsWongyos Keardsri
 

Viewers also liked (20)

Discrete-Chapter 10 Trees
Discrete-Chapter 10 TreesDiscrete-Chapter 10 Trees
Discrete-Chapter 10 Trees
 
Trees (slides)
Trees (slides)Trees (slides)
Trees (slides)
 
Tree (Data Structure & Discrete Mathematics)
Tree (Data Structure & Discrete Mathematics)Tree (Data Structure & Discrete Mathematics)
Tree (Data Structure & Discrete Mathematics)
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Tree in Discrete structure
Tree in Discrete structureTree in Discrete structure
Tree in Discrete structure
 
Relations digraphs
Relations  digraphsRelations  digraphs
Relations digraphs
 
Avltrees
AvltreesAvltrees
Avltrees
 
Discrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIDiscrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part II
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Tree
 
Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphs
 
Traversals | Data Structures
Traversals | Data StructuresTraversals | Data Structures
Traversals | Data Structures
 
Lattices AND Hasse Diagrams
Lattices AND Hasse DiagramsLattices AND Hasse Diagrams
Lattices AND Hasse Diagrams
 
1.4 expression tree
1.4 expression tree  1.4 expression tree
1.4 expression tree
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 
Discrete math ppt
Discrete math pptDiscrete math ppt
Discrete math ppt
 
Tree
TreeTree
Tree
 
Relations in Discrete Math
Relations in Discrete MathRelations in Discrete Math
Relations in Discrete Math
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Discrete-Chapter 05 Inference and Proofs
Discrete-Chapter 05 Inference and ProofsDiscrete-Chapter 05 Inference and Proofs
Discrete-Chapter 05 Inference and Proofs
 

Similar to Discrete Mathematics Tree

Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana Shaikh
 
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
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptxRahulAI
 
tree traversals.pdf
tree traversals.pdftree traversals.pdf
tree traversals.pdfMaryJacob24
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphRai University
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graphRai University
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graphRai University
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)SURBHI SAROHA
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree dsViji B
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxansariparveen06
 
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
 

Similar to Discrete Mathematics Tree (20)

Lecture 5 trees
Lecture 5 treesLecture 5 trees
Lecture 5 trees
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
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
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptx
 
tree traversals.pdf
tree traversals.pdftree traversals.pdf
tree traversals.pdf
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
 
Data structures 3
Data structures 3Data structures 3
Data structures 3
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Module 8.1 Trees.pdf
Module 8.1 Trees.pdfModule 8.1 Trees.pdf
Module 8.1 Trees.pdf
 
Tree
TreeTree
Tree
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptx
 
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
 

More from Masud Parvaze

More from Masud Parvaze (6)

Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Higher order math
Higher order mathHigher order math
Higher order math
 
The end of something11
The end of something11The end of something11
The end of something11
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Mechanism of-a-capacitor
Mechanism of-a-capacitorMechanism of-a-capacitor
Mechanism of-a-capacitor
 
Galvanmometer
Galvanmometer Galvanmometer
Galvanmometer
 

Recently uploaded

Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsDILIPKUMARMONDAL6
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 

Recently uploaded (20)

Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teams
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 

Discrete Mathematics Tree

  • 1. Introduction to Tree • Fundamental data storage structures used in programming. • Combines advantages of an ordered array and a linked list. • Searching as fast as in ordered array. • Insertion and deletion as fast as in linked list.
  • 3. Tree characteristics • Consists of nodes connected by edges. • Nodes often represent entities (complex objects) such as people, car parts etc. • Edges between the nodes represent the way the nodes are related. • Its easy for a program to get from one node to another if there is a line connecting them. • The only way to get from node to node is to follow a path along the edges.
  • 4. Tree Terminology • Path: Traversal from node to node along the edges results in a sequence called path. • Root: Node at the top of the tree. • Parent: Any node, except root has exactly one edge running upward to another node. The node above it is called parent. • Child: Any node may have one or more lines running downward to other nodes. Nodes below are children. • Leaf: A node that has no children. • Subtree: Any node can be considered to be the root of a subtree, which consists of its children and its children’s children and so on.
  • 5. Tree Terminology • Visiting: A node is visited when program control arrives at the node, usually for processing. • Traversing: To traverse a tree means to visit all the nodes in some specified order. • Levels: The level of a particular node refers to how many generations the node is from the root. Root is assumed to be level 0. • Keys: Key value is used to search for the item or perform other operations on it.
  • 6. Leaf • A vertex is called a leaf if it has no children. 6
  • 7. 7 Owner Jake Manager Brad Chef Carol Waitress Waiter Cook Helper Joyce Chris Max Len Leaf nodes have no children LEAF NODES
  • 8. 8 Owner Jake Manager Brad Chef Carol Waitress Waiter Cook Helper Joyce Chris Max Len A Subtree LEFT SUBTREE OF ROOT ROOT
  • 9. 9 Owner Jake Manager Brad Chef Carol Waitress Waiter Cook Helper Joyce Chris Max Len Another Subtree RIGHT SUBTREE OF ROOT ROOT
  • 10. m-ary trees A rooted tree is called an m-ary tree if every internal vertex has no more than m children. The tree is called a full m-ary tree if every internal vertex has exactly m children. An m-ary tree with m=2 is called a binary tree.
  • 11.
  • 12. Ordered Rooted Tree An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. Ordered trees are drawn so that the children of each internal vertex are shown in order from left to right.
  • 13. Properties of Trees A tree with n vertices has n-1 edges.
  • 14. Properties of Trees A full m-ary tree with i internal vertices contains n = mi+1 vertices.
  • 15. Properties of Trees A full m-ary tree with (i) n vertices has i = (n-1)/m internal vertices and l = [(m-1)n+1]/m leaves. (ii) i internal vertices has n = mi + 1 vertices and l = (m-1)i + 1 leaves. (iii) l leaves has n = (ml - 1)/(m-1) vertices and i = (l-1)/(m-1) internal vertices.
  • 16. Proof • We know n = mi+1 (previous theorem) and n = l+i, • n – no. vertices • i – no. internal vertices • l – no. leaves • For example, i = (n-1)/m
  • 17. Properties of Trees The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. level 2 level 3
  • 18. Properties of Trees The height of a rooted tree is the maximum of the levels of vertices.
  • 19. Properties of Trees A rooted m-ary tree of height h is called balanced if all leaves are at levels h or h-1.
  • 20. Properties of Trees There are at most mh leaves in an m-ary tree of height h.
  • 21. Properties of Trees If an m-ary tree of height h has l leaves, then  h lm log
  • 22. Proof • From previous theorem:   hlhlml mm h  loglog
  • 23. Minimum Spanning Tree • Input: A connected, undirected graph G = (V, E) with weight function w : E  R. • For simplicity, we assume that all edge weights are distinct. • Output: A spanning tree T, a tree that connects all vertices, of minimum weight:    Tvu vuwTw ),( ),()(
  • 24. Example of MST 6 12 5 14 3 8 10 15 9 7
  • 25. Kruskal’s Algorithm It is a greedy algorithm.  In Kruskal’s algorithm, the set A is a forest.  The safe edge is added to A is always a  least-weight edge in the graph that connects two distinct Components.
  • 26. Kruskal’s Algorithm  The operation FIND-SET(u) returns a representative element from the set that contains u.  Thus we can determine whether two vertices u and v belong the same tree by testing whether FIND-SET(u) = FIND-SET(v)  The combining of trees is accomplished by the UNION procedure
  • 27. Kruskal’s Algorithm 1. A   2. for each vertex v  V[G] 3.do MAKE-SET(v) 4.short the edges of E into non-decreasing order by weight. 5.for each edge (u, v)  E, taken in non-decreasing or by weight. 6.do if FIND-SET(u) != FIND-SET(v) 7. then, A  A U {(u, v)} 8. UNION(u, v) 9.return A