SlideShare a Scribd company logo
1 of 36
TREES
DMT 1023 DISCRETE MATHEMATICS
DMT 1023 DISCRETE MATHEMATICS 1
INTRODUCTION
A (free) tree T is
 A simple graph
such that for
every pair of
vertices v and w
 there is a unique
path from v to w
DMT 1023 DISCRETE MATHEMATICS 2
Rooted tree
A rooted tree is a tree
where one of its vertices is
designated the root
DMT 1023 DISCRETE MATHEMATICS 3
Level of a vertex and tree
height
Let T be a rooted tree:
 The level l(v) of a vertex v is
the length of the simple path
from v to the root of the tree
 The height h of a rooted tree T
is the maximum of all level
numbers of its vertices:
h = max { l(v) }
v  V(T)
 Example:
 the tree on the right has height 3
DMT 1023 DISCRETE MATHEMATICS 4
Organizational charts
DMT 1023 DISCRETE MATHEMATICS 5
Huffman codes
 On the left tree the word rate is encoded
001 000 011 100
 On the right tree, the same word rate is encoded
11 000 001 10
DMT 1023 DISCRETE MATHEMATICS 6
IMPORTANT TERMINOLOGY
 Parent
 Ancestor
 Child
 Descendant
 Siblings
 Terminal vertices
 Internal vertices
 Subtrees
DMT 1023 DISCRETE MATHEMATICS 7
Internal and external vertices
 An internal vertex is a
vertex that has at least one
child
 A terminal vertex is a
vertex that has no children
 The tree in the example
has 4 internal vertices and
4 terminal vertices
DMT 1023 DISCRETE MATHEMATICS 8
Subtrees
A subtree of a tree T is a tree T' such that
 V(T')  V(T) and
 E(T')  E(T)
DMT 1023 DISCRETE MATHEMATICS 9
Characterization of trees
Theorem 7.1
If T is a graph with n vertices, the following are
equivalent:
a) T is a tree
b) T is connected and acyclic
 (“acyclic” = having no cycles)
c) T is connected and has n-1 edges
d) T is acyclic and has n-1 edges
DMT 1023 DISCRETE MATHEMATICS 10
SPANNING TREES
Given a graph G, a tree T is a
spanning tree of G if:
 T is a subgraph of G
and
 T contains all the vertices of G
DMT 1023 DISCRETE MATHEMATICS 11
Spanning tree search
 Breadth-first search
method
 Depth-first search
method (backtracking)
DMT 1023 DISCRETE MATHEMATICS 12
MINIMAL SPANNING TREES
Given a weighted graph G, a
minimum spanning tree is
 a spanning tree of G
 that has minimum “weight”
DMT 1023 DISCRETE MATHEMATICS 13
1. Prim’s algorithm
 Step 0: Pick any vertex as a
starting vertex (call it a). T = {a}.
 Step 1: Find the edge with
smallest weight incident to a.
Add it to T Also include in T the
next vertex and call it b.
 Step 2: Find the edge of
smallest weight incident to
either a or b. Include in T that
edge and the next incident
vertex. Call that vertex c.
 Step 3: Repeat Step
2, choosing the edge
of smallest weight
that does not form a
cycle until all vertices
are in T. The resulting
subgraph T is a
minimum spanning
tree.
DMT 1023 DISCRETE MATHEMATICS 14
2. Kruskal’s algorithm
 Step 1: Find the edge in
the graph with smallest
weight (if there is more
than one, pick one at
random). Mark it with any
given color, say red.
 Step 2: Find the next
edge in the graph with
smallest weight that
doesn't close a cycle.
Color that edge and the
next incident vertex.
 Step 3: Repeat Step 2 until
you reach out to every vertex
of the graph. The chosen
edges form the desired
minimum spanning tree.
DMT 1023 DISCRETE MATHEMATICS 15
BINARY TREES
A binary tree is a tree
where each vertex has
zero, one or two children
DMT 1023 DISCRETE MATHEMATICS 16
Full binary tree
A full binary tree is a
binary tree in which
each vertex has two
or no children.
DMT 1023 DISCRETE MATHEMATICS 17
Full binary tree
Theorem 7.2:
If T is a full binary tree with k
internal vertices, then
 T has k + 1 terminal vertices
and
 the total number of vertices
is 2k + 1.
 Example: there are k = 4 internal
vertices (a, b, c and f) and 5
terminal vertices (d, e, g, h and i) for
a total of 9 vertices.
DMT 1023 DISCRETE MATHEMATICS 18
Height and terminal vertices
 Theorem 7.3:
If a binary tree of height h
has t terminal vertices, then
lg t < h, where lg is
logarithm base 2.
Equivalently, t < 2h.
 Example, h = 4 and t = 7.
Then: t = 7 < 16 = 24 = 2h
DMT 1023 DISCRETE MATHEMATICS 19
A case of equality
 If all t terminal vertices of a full
binary tree T have the same
level h = height of T, then
t = 2h.
 Example:
 The height is h = 3,
 and the number of terminal
vertices is t = 8
 t = 8 = 23 = 2h
DMT 1023 DISCRETE MATHEMATICS 20
Alphabetical order
Alphabetical or lexicographic order is the order
of the dictionary:
a) start with an ordered set of symbols X =
{a,b,c, …}. X can be infinite or finite.
b) Let  = x1x2…xm and  = y1y2…yn be strings
over X. Then define  <  if
 x1 < y1
 or if xj= yj for all j, 1 < j < k, for some k such that
1 < k < min{m,n} and xj+1 < yj+1
 or if m < n and xj = yj for all j, 1 < j < m
DMT 1023 DISCRETE MATHEMATICS 21
Example of alphabetical order
 Let X = set of letters of the alphabet ordered
according to precedence, i.e.
a < b < c <… < x < y < z
 Let  = arboreal and  = arbiter.
 In this case,
 x1 = y1 = a,
 x2 = y2 = r
 x3 = y3 = b.
 So, we go the fourth letter: x4 = o and y4 = i.
 Since i < o we have that  < .
DMT 1023 DISCRETE MATHEMATICS 22
Binary search trees
 Data are associated to
each vertex
 Order data alphabetically,
so that for each vertex v,
data to the left of v are
less than data in v
 and data to the right of v
are greater than data in v
 Example:
"Computers are an
important
technological tool"
DMT 1023 DISCRETE MATHEMATICS 23
TREE TRAVERSALS
 1: Pre-order traversal
 2: In-order traversal
DMT 1023 DISCRETE MATHEMATICS 24
More on tree traversals
 3: Post-order traversal
 4: Reverse post-order
traversal
DMT 1023 DISCRETE MATHEMATICS 25
DECISION TREES
A decision tree is a binary tree containing an
algorithm to decide which course of action to
take.
DMT 1023 DISCRETE MATHEMATICS 26
ISOMORPHISM OF TREES
Given two trees T1 and T2
 T1 is isomorphic to T2
 if we can find a one-to-one and
onto function f :T1 → T2
 that preserves the adjacency
relation
 i.e. if v, w  V(T1) and e = (v, w) is an
edge in T1, then e’ = (f(v), f(w)) is an
edge in T2.
DMT 1023 DISCRETE MATHEMATICS 27
Isomorphism of rooted trees
Let T1 and T2 be rooted trees with roots r1 and
r2, respectively. T1 and T2 are isomorphic as
rooted trees if
 there is a one-to-one function f: V(T1) V(T2)
such that vertices v and w are adjacent in T1 if
and only if f(v) and f(w) are adjacent in T2
 f(r1) = r2
Example:
 T1 and T2 are isomorphic
as rooted trees
DMT 1023 DISCRETE MATHEMATICS 28
Isomorphism of binary trees
Let T1 and T2 be binary trees with roots r1 and r2,
respectively. T1 and T2 are isomorphic as binary
trees if
a) T1 and T2 are isomorphic as rooted trees
through an isomorphism f, and
b) v is a left (right) child in T1 if and only if f(v) is
a left (right) child in T2
 Note: This condition is more restrictive that isomorphism only as
rooted trees. Left children must be mapped onto left children
and right children must be mapped onto right children.
DMT 1023 DISCRETE MATHEMATICS 29
Binary tree isomorphism
Example: the following two trees are
 isomorphic as rooted trees, but
 not isomorphic as binary trees
DMT 1023 DISCRETE MATHEMATICS 30
Summary of tree
isomorphism
There are 3 kinds of tree isomorphism
 Isomorphism of trees
 Isomorphism of rooted trees
 (root goes to root)
 Isomorphism of binary trees
 (left children go to left children, right children go to
right children)
DMT 1023 DISCRETE MATHEMATICS 31
Non-isomorphism of trees
 Many times it may be easier to determine
when two trees are not isomorphic rather than
to show their isomorphism.
 A tree isomorphism must respect certain
properties, such as
 the number of vertices
 the number of edges
 the degrees of corresponding vertices
 roots must go to roots
 position of children, etc.
DMT 1023 DISCRETE MATHEMATICS 32
Non-isomorphism of rooted trees
Theorem 7.4:
There are four non-isomorphic rooted trees with
four vertices.
 The root is the top vertex in each tree.
 The degrees of the vertices appear in parenthesis
DMT 1023 DISCRETE MATHEMATICS 33
Non-isomorphic binary trees
Theorem 7.5:
 There are C(2n,n) / (n+1) non-isomorphic
binary trees with n vertices, n > 0, where
 C(2n,n) / (n+1) are the Catalan numbers Cn
DMT 1023 DISCRETE MATHEMATICS 34
Isomorphism of binary trees
There is an algorithm to test whether two binary
trees are isomorphic or not.
 If the number of vertices in the two trees is n,
 and if the number of comparisons needed is an,
it can be shown that an < 3n + 2.
Theorem 7.6: The worst case of this algorithm is
(n).
DMT 1023 DISCRETE MATHEMATICS 35
THE END
DMT 1023 DISCRETE MATHEMATICS 36

More Related Content

Similar to 7 Trees.pptx

7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binarySSE_AndyLi
 
Ireducible core and equal remaining obligations rule for mcst games
Ireducible core and equal remaining obligations rule for mcst gamesIreducible core and equal remaining obligations rule for mcst games
Ireducible core and equal remaining obligations rule for mcst gamesvinnief
 
Explaining the Kruskal Tree Theore
Explaining the Kruskal Tree TheoreExplaining the Kruskal Tree Theore
Explaining the Kruskal Tree TheoreMarco Benini
 
The Chasm at Depth Four, and Tensor Rank : Old results, new insights
The Chasm at Depth Four, and Tensor Rank : Old results, new insightsThe Chasm at Depth Four, and Tensor Rank : Old results, new insights
The Chasm at Depth Four, and Tensor Rank : Old results, new insightscseiitgn
 
Complete l fuzzy metric spaces and common fixed point theorems
Complete l fuzzy metric spaces and  common fixed point theoremsComplete l fuzzy metric spaces and  common fixed point theorems
Complete l fuzzy metric spaces and common fixed point theoremsAlexander Decker
 
EVEN GRACEFUL LABELLING OF A CLASS OF TREES
EVEN GRACEFUL LABELLING OF A CLASS OF TREESEVEN GRACEFUL LABELLING OF A CLASS OF TREES
EVEN GRACEFUL LABELLING OF A CLASS OF TREESFransiskeran
 
Review session2
Review session2Review session2
Review session2NEEDY12345
 
A common fixed point theorem in cone metric spaces
A common fixed point theorem in cone metric spacesA common fixed point theorem in cone metric spaces
A common fixed point theorem in cone metric spacesAlexander Decker
 
Treewidth and Applications
Treewidth and ApplicationsTreewidth and Applications
Treewidth and ApplicationsASPAK2014
 
Characterization of trees with equal total edge domination and double edge do...
Characterization of trees with equal total edge domination and double edge do...Characterization of trees with equal total edge domination and double edge do...
Characterization of trees with equal total edge domination and double edge do...Alexander Decker
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxansariparveen06
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures treemaamir farooq
 
Kirchoff''s matrix tree theorem
Kirchoff''s matrix tree theoremKirchoff''s matrix tree theorem
Kirchoff''s matrix tree theoremSwathiSundari
 

Similar to 7 Trees.pptx (20)

50120140501010
5012014050101050120140501010
50120140501010
 
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binary
 
Ireducible core and equal remaining obligations rule for mcst games
Ireducible core and equal remaining obligations rule for mcst gamesIreducible core and equal remaining obligations rule for mcst games
Ireducible core and equal remaining obligations rule for mcst games
 
fermat_last_theorem.pdf
fermat_last_theorem.pdffermat_last_theorem.pdf
fermat_last_theorem.pdf
 
Explaining the Kruskal Tree Theore
Explaining the Kruskal Tree TheoreExplaining the Kruskal Tree Theore
Explaining the Kruskal Tree Theore
 
The Chasm at Depth Four, and Tensor Rank : Old results, new insights
The Chasm at Depth Four, and Tensor Rank : Old results, new insightsThe Chasm at Depth Four, and Tensor Rank : Old results, new insights
The Chasm at Depth Four, and Tensor Rank : Old results, new insights
 
7.tree
7.tree7.tree
7.tree
 
Complete l fuzzy metric spaces and common fixed point theorems
Complete l fuzzy metric spaces and  common fixed point theoremsComplete l fuzzy metric spaces and  common fixed point theorems
Complete l fuzzy metric spaces and common fixed point theorems
 
trees-and-forest.pdf
trees-and-forest.pdftrees-and-forest.pdf
trees-and-forest.pdf
 
EVEN GRACEFUL LABELLING OF A CLASS OF TREES
EVEN GRACEFUL LABELLING OF A CLASS OF TREESEVEN GRACEFUL LABELLING OF A CLASS OF TREES
EVEN GRACEFUL LABELLING OF A CLASS OF TREES
 
Review session2
Review session2Review session2
Review session2
 
Tree
TreeTree
Tree
 
Taylor's series
 Taylor's  series   Taylor's  series
Taylor's series
 
A common fixed point theorem in cone metric spaces
A common fixed point theorem in cone metric spacesA common fixed point theorem in cone metric spaces
A common fixed point theorem in cone metric spaces
 
MATH225Final
MATH225FinalMATH225Final
MATH225Final
 
Treewidth and Applications
Treewidth and ApplicationsTreewidth and Applications
Treewidth and Applications
 
Characterization of trees with equal total edge domination and double edge do...
Characterization of trees with equal total edge domination and double edge do...Characterization of trees with equal total edge domination and double edge do...
Characterization of trees with equal total edge domination and double edge do...
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptx
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Kirchoff''s matrix tree theorem
Kirchoff''s matrix tree theoremKirchoff''s matrix tree theorem
Kirchoff''s matrix tree theorem
 

Recently uploaded

UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 

Recently uploaded (20)

UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 

7 Trees.pptx

  • 1. TREES DMT 1023 DISCRETE MATHEMATICS DMT 1023 DISCRETE MATHEMATICS 1
  • 2. INTRODUCTION A (free) tree T is  A simple graph such that for every pair of vertices v and w  there is a unique path from v to w DMT 1023 DISCRETE MATHEMATICS 2
  • 3. Rooted tree A rooted tree is a tree where one of its vertices is designated the root DMT 1023 DISCRETE MATHEMATICS 3
  • 4. Level of a vertex and tree height Let T be a rooted tree:  The level l(v) of a vertex v is the length of the simple path from v to the root of the tree  The height h of a rooted tree T is the maximum of all level numbers of its vertices: h = max { l(v) } v  V(T)  Example:  the tree on the right has height 3 DMT 1023 DISCRETE MATHEMATICS 4
  • 5. Organizational charts DMT 1023 DISCRETE MATHEMATICS 5
  • 6. Huffman codes  On the left tree the word rate is encoded 001 000 011 100  On the right tree, the same word rate is encoded 11 000 001 10 DMT 1023 DISCRETE MATHEMATICS 6
  • 7. IMPORTANT TERMINOLOGY  Parent  Ancestor  Child  Descendant  Siblings  Terminal vertices  Internal vertices  Subtrees DMT 1023 DISCRETE MATHEMATICS 7
  • 8. Internal and external vertices  An internal vertex is a vertex that has at least one child  A terminal vertex is a vertex that has no children  The tree in the example has 4 internal vertices and 4 terminal vertices DMT 1023 DISCRETE MATHEMATICS 8
  • 9. Subtrees A subtree of a tree T is a tree T' such that  V(T')  V(T) and  E(T')  E(T) DMT 1023 DISCRETE MATHEMATICS 9
  • 10. Characterization of trees Theorem 7.1 If T is a graph with n vertices, the following are equivalent: a) T is a tree b) T is connected and acyclic  (“acyclic” = having no cycles) c) T is connected and has n-1 edges d) T is acyclic and has n-1 edges DMT 1023 DISCRETE MATHEMATICS 10
  • 11. SPANNING TREES Given a graph G, a tree T is a spanning tree of G if:  T is a subgraph of G and  T contains all the vertices of G DMT 1023 DISCRETE MATHEMATICS 11
  • 12. Spanning tree search  Breadth-first search method  Depth-first search method (backtracking) DMT 1023 DISCRETE MATHEMATICS 12
  • 13. MINIMAL SPANNING TREES Given a weighted graph G, a minimum spanning tree is  a spanning tree of G  that has minimum “weight” DMT 1023 DISCRETE MATHEMATICS 13
  • 14. 1. Prim’s algorithm  Step 0: Pick any vertex as a starting vertex (call it a). T = {a}.  Step 1: Find the edge with smallest weight incident to a. Add it to T Also include in T the next vertex and call it b.  Step 2: Find the edge of smallest weight incident to either a or b. Include in T that edge and the next incident vertex. Call that vertex c.  Step 3: Repeat Step 2, choosing the edge of smallest weight that does not form a cycle until all vertices are in T. The resulting subgraph T is a minimum spanning tree. DMT 1023 DISCRETE MATHEMATICS 14
  • 15. 2. Kruskal’s algorithm  Step 1: Find the edge in the graph with smallest weight (if there is more than one, pick one at random). Mark it with any given color, say red.  Step 2: Find the next edge in the graph with smallest weight that doesn't close a cycle. Color that edge and the next incident vertex.  Step 3: Repeat Step 2 until you reach out to every vertex of the graph. The chosen edges form the desired minimum spanning tree. DMT 1023 DISCRETE MATHEMATICS 15
  • 16. BINARY TREES A binary tree is a tree where each vertex has zero, one or two children DMT 1023 DISCRETE MATHEMATICS 16
  • 17. Full binary tree A full binary tree is a binary tree in which each vertex has two or no children. DMT 1023 DISCRETE MATHEMATICS 17
  • 18. Full binary tree Theorem 7.2: If T is a full binary tree with k internal vertices, then  T has k + 1 terminal vertices and  the total number of vertices is 2k + 1.  Example: there are k = 4 internal vertices (a, b, c and f) and 5 terminal vertices (d, e, g, h and i) for a total of 9 vertices. DMT 1023 DISCRETE MATHEMATICS 18
  • 19. Height and terminal vertices  Theorem 7.3: If a binary tree of height h has t terminal vertices, then lg t < h, where lg is logarithm base 2. Equivalently, t < 2h.  Example, h = 4 and t = 7. Then: t = 7 < 16 = 24 = 2h DMT 1023 DISCRETE MATHEMATICS 19
  • 20. A case of equality  If all t terminal vertices of a full binary tree T have the same level h = height of T, then t = 2h.  Example:  The height is h = 3,  and the number of terminal vertices is t = 8  t = 8 = 23 = 2h DMT 1023 DISCRETE MATHEMATICS 20
  • 21. Alphabetical order Alphabetical or lexicographic order is the order of the dictionary: a) start with an ordered set of symbols X = {a,b,c, …}. X can be infinite or finite. b) Let  = x1x2…xm and  = y1y2…yn be strings over X. Then define  <  if  x1 < y1  or if xj= yj for all j, 1 < j < k, for some k such that 1 < k < min{m,n} and xj+1 < yj+1  or if m < n and xj = yj for all j, 1 < j < m DMT 1023 DISCRETE MATHEMATICS 21
  • 22. Example of alphabetical order  Let X = set of letters of the alphabet ordered according to precedence, i.e. a < b < c <… < x < y < z  Let  = arboreal and  = arbiter.  In this case,  x1 = y1 = a,  x2 = y2 = r  x3 = y3 = b.  So, we go the fourth letter: x4 = o and y4 = i.  Since i < o we have that  < . DMT 1023 DISCRETE MATHEMATICS 22
  • 23. Binary search trees  Data are associated to each vertex  Order data alphabetically, so that for each vertex v, data to the left of v are less than data in v  and data to the right of v are greater than data in v  Example: "Computers are an important technological tool" DMT 1023 DISCRETE MATHEMATICS 23
  • 24. TREE TRAVERSALS  1: Pre-order traversal  2: In-order traversal DMT 1023 DISCRETE MATHEMATICS 24
  • 25. More on tree traversals  3: Post-order traversal  4: Reverse post-order traversal DMT 1023 DISCRETE MATHEMATICS 25
  • 26. DECISION TREES A decision tree is a binary tree containing an algorithm to decide which course of action to take. DMT 1023 DISCRETE MATHEMATICS 26
  • 27. ISOMORPHISM OF TREES Given two trees T1 and T2  T1 is isomorphic to T2  if we can find a one-to-one and onto function f :T1 → T2  that preserves the adjacency relation  i.e. if v, w  V(T1) and e = (v, w) is an edge in T1, then e’ = (f(v), f(w)) is an edge in T2. DMT 1023 DISCRETE MATHEMATICS 27
  • 28. Isomorphism of rooted trees Let T1 and T2 be rooted trees with roots r1 and r2, respectively. T1 and T2 are isomorphic as rooted trees if  there is a one-to-one function f: V(T1) V(T2) such that vertices v and w are adjacent in T1 if and only if f(v) and f(w) are adjacent in T2  f(r1) = r2 Example:  T1 and T2 are isomorphic as rooted trees DMT 1023 DISCRETE MATHEMATICS 28
  • 29. Isomorphism of binary trees Let T1 and T2 be binary trees with roots r1 and r2, respectively. T1 and T2 are isomorphic as binary trees if a) T1 and T2 are isomorphic as rooted trees through an isomorphism f, and b) v is a left (right) child in T1 if and only if f(v) is a left (right) child in T2  Note: This condition is more restrictive that isomorphism only as rooted trees. Left children must be mapped onto left children and right children must be mapped onto right children. DMT 1023 DISCRETE MATHEMATICS 29
  • 30. Binary tree isomorphism Example: the following two trees are  isomorphic as rooted trees, but  not isomorphic as binary trees DMT 1023 DISCRETE MATHEMATICS 30
  • 31. Summary of tree isomorphism There are 3 kinds of tree isomorphism  Isomorphism of trees  Isomorphism of rooted trees  (root goes to root)  Isomorphism of binary trees  (left children go to left children, right children go to right children) DMT 1023 DISCRETE MATHEMATICS 31
  • 32. Non-isomorphism of trees  Many times it may be easier to determine when two trees are not isomorphic rather than to show their isomorphism.  A tree isomorphism must respect certain properties, such as  the number of vertices  the number of edges  the degrees of corresponding vertices  roots must go to roots  position of children, etc. DMT 1023 DISCRETE MATHEMATICS 32
  • 33. Non-isomorphism of rooted trees Theorem 7.4: There are four non-isomorphic rooted trees with four vertices.  The root is the top vertex in each tree.  The degrees of the vertices appear in parenthesis DMT 1023 DISCRETE MATHEMATICS 33
  • 34. Non-isomorphic binary trees Theorem 7.5:  There are C(2n,n) / (n+1) non-isomorphic binary trees with n vertices, n > 0, where  C(2n,n) / (n+1) are the Catalan numbers Cn DMT 1023 DISCRETE MATHEMATICS 34
  • 35. Isomorphism of binary trees There is an algorithm to test whether two binary trees are isomorphic or not.  If the number of vertices in the two trees is n,  and if the number of comparisons needed is an, it can be shown that an < 3n + 2. Theorem 7.6: The worst case of this algorithm is (n). DMT 1023 DISCRETE MATHEMATICS 35
  • 36. THE END DMT 1023 DISCRETE MATHEMATICS 36