SlideShare a Scribd company logo
1 of 7
Page 1 of 7
ASSIGNMENT TOPIC :
TREES IN DISCRETE STRUCTURE
DISCIPLINE :
BS (HONS)COMPUTER SCIENCES
SUBMITTED BY :
KHADIJA TAHIRA 043
SUBMITTED TO :
MA’AM NOSHEEN ILYAS
Page 2 of 7
TREE IN DISCRETE STRUCTURE
Tree is a discrete structure that represents hierarchical relationships between individual elements
or nodes. A tree in which a parent has no more than two children is called a binary tree.
Tree and its Properties
A Tree is a connected acyclic undirected graph. There is a unique path between every pair of
vertices in GG. A tree with N number of vertices contains (N−1)(N−1) number of edges. The
vertex which is of 0 degree is called root of the tree. The vertex which is of 1 degree is called leaf
node of the tree and the degree of an internal node is at least 2.
Example − The following is an example of a tree −
Centers and Bi-Centers of a Tree
The center of a tree is a vertex with minimal eccentricity. The eccentricity of a vertex XX in a
tree GG is the maximum distance between the vertex XX and any other vertex of the tree. The
maximum eccentricity is the tree diameter. If a tree has only one center, it is called Central Tree
and if a tree has only more than one centers, it is called Bi-central Tree. Every tree is either central
or bi-central.
Algorithm to find centers and bi-centers of a tree
Step 1 − Remove all the vertices of degree 1 from the given tree and also remove their incident
edges.
Step 2 − Repeat step 1 until either a single vertex or two vertices joined by an edge is left. If a
single vertex is left then it is the center of the tree and if two vertices joined by an edge is left then
it is the bi-center of the tree.
Page 3 of 7
Problem 1
Find out the center/bi-center of the following tree −
Solution
At first, we will remove all vertices of degree 1 and also remove their incident edges and get the
following tree –
Again, we will remove all vertices of degree 1 and also remove their incident edges and get the
following tree −
Finally we got a single vertex ‘c’ and we stop the algorithm. As there is single vertex, this tree
has one center ‘c’ and the tree is a central tree.
Page 4 of 7
Problem 2
Find out the center/bi-center of the following tree –
Solution
At first, we will remove all vertices of degree 1 and also remove their incident edges and get the
following tree −
Again, we will remove all vertices of degree 1 and also remove their incident edges and get the
following tree −
Finally, we got two vertices ‘c’ and ‘d’ left, hence we stop the algorithm. As two vertices joined
by an edge is left, this tree has bi-center ‘cd’ and the tree is bi-central.
Page 5 of 7
Labeled Trees
A labeled tree is a tree the vertices of which are assigned unique numbers from 1 to n. We can
count such trees for small values of n by hand so as to conjecture a general formula. The number
of labeled trees of n number of vertices is nn−2nn−2. Two labeled trees are isomorphic if their
graphs are isomorphic and the corresponding points of the two trees have the same labels.
Example
Unlabeled Trees
An unlabeled tree is a tree the vertices of which are not assigned any numbers. The number of
labeled trees of n number of vertices is (2n)!(n+1)!n!(2n)!(n+1)!n! (nth Catalan number)
Example
Page 6 of 7
Rooted Tree
A rooted tree GG is a connected acyclic graph with a special node that is called the root of the
tree and every edge directly or indirectly originates from the root. An ordered rooted tree is a
rooted tree where the children of each internal vertex are ordered. If every internal vertex of a
rooted tree has not more than m children, it is called an m-ary tree. If every internal vertex of a
rooted tree has exactly m children, it is called a full m-ary tree. If m=2m=2, the rooted tree is
called a binary tree.
Page 7 of 7
Binary Search Tree
Binary Search tree is a binary tree which satisfies the following property −
 XX in left sub-tree of vertex V,Value(X)≤Value(V)V,Value(X)≤Value(V)
 YY in right sub-tree of vertex V,Value(Y)≥Value(V)V,Value(Y)≥Value(V)
So, the value of all the vertices of the left sub-tree of an internal node VV are less than or equal
to VV and the value of all the vertices of the right sub-tree of the internal node VV are greater
than or equal to VV. The number of links from the root node to the deepest node is the height of
the Binary Search Tree.
Example

More Related Content

What's hot

A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmGaurav Kolekar
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - GraphMadhu Bala
 
Binary Tree Representation in memory
Binary Tree Representation in memoryBinary Tree Representation in memory
Binary Tree Representation in memoryMohit Jain
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphssana younas
 
2 3 Trees Algorithm - Data Structure
2 3 Trees Algorithm - Data Structure2 3 Trees Algorithm - Data Structure
2 3 Trees Algorithm - Data StructureTish997
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data StructuresAdarsh Patel
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patilwidespreadpromotion
 

What's hot (20)

Binary tree
Binary  treeBinary  tree
Binary tree
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithm
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Tree
TreeTree
Tree
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
B tree
B treeB tree
B tree
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Binary Tree Representation in memory
Binary Tree Representation in memoryBinary Tree Representation in memory
Binary Tree Representation in memory
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphs
 
Linked list
Linked listLinked list
Linked list
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 
2 3 Trees Algorithm - Data Structure
2 3 Trees Algorithm - Data Structure2 3 Trees Algorithm - Data Structure
2 3 Trees Algorithm - Data Structure
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data Structures
 
Decision tree
Decision treeDecision tree
Decision tree
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
 
Kruskal’s algorithm
Kruskal’s algorithmKruskal’s algorithm
Kruskal’s algorithm
 

Similar to Tree in discrete structure

B.TECH Math project
B.TECH Math projectB.TECH Math project
B.TECH Math projectarunsarkar9
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptxAbirami A
 
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
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana Shaikh
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2smruti sarangi
 
Pattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_treesPattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_treesNathan Gabriel
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxansariparveen06
 
Basic Terminologies of Tree and Tree Traversal methods.pptx
Basic Terminologies of Tree and Tree Traversal methods.pptxBasic Terminologies of Tree and Tree Traversal methods.pptx
Basic Terminologies of Tree and Tree Traversal methods.pptx22001003058
 
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
 
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
 
Describe the tree data structure- What is a root node- What is a child.docx
Describe the tree data structure- What is a root node- What is a child.docxDescribe the tree data structure- What is a root node- What is a child.docx
Describe the tree data structure- What is a root node- What is a child.docxandyb37
 

Similar to Tree in discrete structure (20)

B.TECH Math project
B.TECH Math projectB.TECH Math project
B.TECH Math project
 
Tree
TreeTree
Tree
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Lecture 5 trees
Lecture 5 treesLecture 5 trees
Lecture 5 trees
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
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.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
DSA IV Unit.pptx
DSA IV Unit.pptxDSA IV Unit.pptx
DSA IV Unit.pptx
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
M ary-tree
M ary-treeM ary-tree
M ary-tree
 
Pattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_treesPattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_trees
 
Trees
TreesTrees
Trees
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
trees-and-forest.pdf
trees-and-forest.pdftrees-and-forest.pdf
trees-and-forest.pdf
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptx
 
Basic Terminologies of Tree and Tree Traversal methods.pptx
Basic Terminologies of Tree and Tree Traversal methods.pptxBasic Terminologies of Tree and Tree Traversal methods.pptx
Basic Terminologies of Tree and Tree Traversal methods.pptx
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.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
 
Describe the tree data structure- What is a root node- What is a child.docx
Describe the tree data structure- What is a root node- What is a child.docxDescribe the tree data structure- What is a root node- What is a child.docx
Describe the tree data structure- What is a root node- What is a child.docx
 

More from Lahore Garrison University (20)

Sigmund freud
Sigmund freudSigmund freud
Sigmund freud
 
Application of de
Application of deApplication of de
Application of de
 
Firm practice management
Firm practice managementFirm practice management
Firm practice management
 
Mapping functions
Mapping functionsMapping functions
Mapping functions
 
Project dld
Project dldProject dld
Project dld
 
Python cheatsheet for beginners
Python cheatsheet for beginnersPython cheatsheet for beginners
Python cheatsheet for beginners
 
Ak
AkAk
Ak
 
Ternary operator
Ternary operatorTernary operator
Ternary operator
 
Bussines plan (maira)
Bussines plan (maira)Bussines plan (maira)
Bussines plan (maira)
 
8. file handling
8. file handling8. file handling
8. file handling
 
Project# 1
Project# 1Project# 1
Project# 1
 
Shares & stock market
Shares & stock marketShares & stock market
Shares & stock market
 
Ozone layer research paper (1)
Ozone layer research paper (1)Ozone layer research paper (1)
Ozone layer research paper (1)
 
Introduction to information and communication technology
Introduction to information and communication technologyIntroduction to information and communication technology
Introduction to information and communication technology
 
Ict
IctIct
Ict
 
Forty rulesoflove review writing
Forty rulesoflove review writingForty rulesoflove review writing
Forty rulesoflove review writing
 
Semester 1 exercise for punctuation mark
Semester 1 exercise for punctuation markSemester 1 exercise for punctuation mark
Semester 1 exercise for punctuation mark
 
Scan apr 8, 2020 (1)
Scan apr 8, 2020 (1)Scan apr 8, 2020 (1)
Scan apr 8, 2020 (1)
 
Reading skill
Reading skill Reading skill
Reading skill
 
Quiz
Quiz Quiz
Quiz
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Tree in discrete structure

  • 1. Page 1 of 7 ASSIGNMENT TOPIC : TREES IN DISCRETE STRUCTURE DISCIPLINE : BS (HONS)COMPUTER SCIENCES SUBMITTED BY : KHADIJA TAHIRA 043 SUBMITTED TO : MA’AM NOSHEEN ILYAS
  • 2. Page 2 of 7 TREE IN DISCRETE STRUCTURE Tree is a discrete structure that represents hierarchical relationships between individual elements or nodes. A tree in which a parent has no more than two children is called a binary tree. Tree and its Properties A Tree is a connected acyclic undirected graph. There is a unique path between every pair of vertices in GG. A tree with N number of vertices contains (N−1)(N−1) number of edges. The vertex which is of 0 degree is called root of the tree. The vertex which is of 1 degree is called leaf node of the tree and the degree of an internal node is at least 2. Example − The following is an example of a tree − Centers and Bi-Centers of a Tree The center of a tree is a vertex with minimal eccentricity. The eccentricity of a vertex XX in a tree GG is the maximum distance between the vertex XX and any other vertex of the tree. The maximum eccentricity is the tree diameter. If a tree has only one center, it is called Central Tree and if a tree has only more than one centers, it is called Bi-central Tree. Every tree is either central or bi-central. Algorithm to find centers and bi-centers of a tree Step 1 − Remove all the vertices of degree 1 from the given tree and also remove their incident edges. Step 2 − Repeat step 1 until either a single vertex or two vertices joined by an edge is left. If a single vertex is left then it is the center of the tree and if two vertices joined by an edge is left then it is the bi-center of the tree.
  • 3. Page 3 of 7 Problem 1 Find out the center/bi-center of the following tree − Solution At first, we will remove all vertices of degree 1 and also remove their incident edges and get the following tree – Again, we will remove all vertices of degree 1 and also remove their incident edges and get the following tree − Finally we got a single vertex ‘c’ and we stop the algorithm. As there is single vertex, this tree has one center ‘c’ and the tree is a central tree.
  • 4. Page 4 of 7 Problem 2 Find out the center/bi-center of the following tree – Solution At first, we will remove all vertices of degree 1 and also remove their incident edges and get the following tree − Again, we will remove all vertices of degree 1 and also remove their incident edges and get the following tree − Finally, we got two vertices ‘c’ and ‘d’ left, hence we stop the algorithm. As two vertices joined by an edge is left, this tree has bi-center ‘cd’ and the tree is bi-central.
  • 5. Page 5 of 7 Labeled Trees A labeled tree is a tree the vertices of which are assigned unique numbers from 1 to n. We can count such trees for small values of n by hand so as to conjecture a general formula. The number of labeled trees of n number of vertices is nn−2nn−2. Two labeled trees are isomorphic if their graphs are isomorphic and the corresponding points of the two trees have the same labels. Example Unlabeled Trees An unlabeled tree is a tree the vertices of which are not assigned any numbers. The number of labeled trees of n number of vertices is (2n)!(n+1)!n!(2n)!(n+1)!n! (nth Catalan number) Example
  • 6. Page 6 of 7 Rooted Tree A rooted tree GG is a connected acyclic graph with a special node that is called the root of the tree and every edge directly or indirectly originates from the root. An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. If every internal vertex of a rooted tree has not more than m children, it is called an m-ary tree. If every internal vertex of a rooted tree has exactly m children, it is called a full m-ary tree. If m=2m=2, the rooted tree is called a binary tree.
  • 7. Page 7 of 7 Binary Search Tree Binary Search tree is a binary tree which satisfies the following property −  XX in left sub-tree of vertex V,Value(X)≤Value(V)V,Value(X)≤Value(V)  YY in right sub-tree of vertex V,Value(Y)≥Value(V)V,Value(Y)≥Value(V) So, the value of all the vertices of the left sub-tree of an internal node VV are less than or equal to VV and the value of all the vertices of the right sub-tree of the internal node VV are greater than or equal to VV. The number of links from the root node to the deepest node is the height of the Binary Search Tree. Example