SlideShare a Scribd company logo
Tree
s
Chapter Summary
• Introduction to Trees
• Applications of Trees
• Tree Traversal
• Spanning Trees
• Minimum Spanning
Introduction to Trees
Section
Section Summary
• Introduction to Trees
• Rooted Trees
• Trees as Models
• Properties of Trees
Tree
s
Definition: A tree is a connected undirected graph with no simple
circuits.
Definition: An undirected graph is a tree if and only if there is a
unique simple path between any two of its vertices. A tree cannot
contain multiple edges or loops.
Definition: An undirected graph is a tree if and only if there is a
unique simple path between any two of its vertices.
Trees
Example: Which of these graphs are trees?
Solution: G and G are trees - both are connected and have no
simple circuits. G is not a tree because e, b, a, d, e is a simple
circuit,. G is not a tree because it is not connected.
FOREST
Definition: A forest is a graph that has no simple circuit, but is not
connected. Each of the connected components in a forest is a tree.
Applications of Trees
Section
Trees as Models
• Trees are used as models in computer science, chemistry, geology,
botany, psychology, and many other areas.
• Trees were introduced by the mathematician Cayley in in
his work counting the number of isomers of saturated
hydrocarbons. The two isomers of butane are:.
Arthur Cayley
( )
Trees as Models
• The organization of a computer file system into directories,
subdirectories, and files is naturally represented as a tree.
Trees as Models
• Trees are used to represent the structure of organizations.
Applications of Trees
•Game Trees
Trees can be used to analyze certain types of games
such as tic-tac-toe, nim, checkers, and chess.
Game Tree for Tic-Tac-Toe
Universal Address Systems
Prefix
code
Definition: A code that has the property that
the code of a character is never a prefix of the
code of another character.
• A prefix code can be represented using a
binary tree, where the characters are the
labels of the leaves in the tree.
• The edges of the tree are labeled so that an
edge leading to a left child is assigned a 0 and
an edge leading to a right child is assigned a
1.
• The bit string used to encode a character is
the sequence of labels of the edges in the
unique path from the root to the leaf that has
this character as its label.
• For instance, the tree in Figure 5 represents
the encoding of e by 0, a by 10, t by 110, n by
1110, and s by 1111.
Decision Trees
Definition: A rooted tree where each vertex represents a
possible outcome of a decision and the leaves represent the
possible solutions of a problem.
• Rooted trees can be used to model problems in which a series
of decisions leads to a solution.
• The possible solutions of the problem correspond to the paths
to the leaves of this rooted tree.
Example : A decision tree that orders the elements of
the list a, b, c.
Rooted Trees
Definition: A rooted tree is a tree in which one vertex has been
designated as the root and every edge is directed away from the
root.
• An unrooted tree is converted into different rooted trees when
different vertices are chosen as the root.
Rooted Tree Terminology
• Terminology for rooted trees is a mix from botany and genealogy (such as
this family tree of the Bernoulli family of mathematicians).
Rooted Tree Terminology
• If v is a vertex of a rooted tree other than the root, the parent of v is the unique
vertex u such that there is a directed edge from u to v. When u is a parent of v, v
is called a child of u. Vertices with the same parent are called siblings.
Rooted Tree Terminology
• The ancestors of a vertex are the vertices in the path from the root to this
vertex, excluding the vertex itself and including the root.
• The descendants of a vertex v are those vertices that have v as an ancestor. The
subtree rooted at u includes all the descendants of u, and all edges that connect
between them.
Rooted Tree Terminology
• A vertex of a rooted tree with no children is called a leaf. Vertices that have
children are called internal vertices.
Terminology for Rooted Trees
Example: In the rooted tree T (with
root a):
(i) Find the parent of c, the children
of g, the siblings of h, the
ancestors of e, and the
descendants of b.
Solution:
(i) The parent of c is b. The children
of g are h, i, and j. The siblings
of h are i and j. The ancestors of
e are c, b, and a. The
descendants of b are c, d, and e.
Terminology for Rooted Trees
Example: In the rooted tree T
(with root a):
(i) Find all internal
vertices and all leaves.
Solution:
(i) The internal vertices are
a, b, c, g, h, and j. The
leaves are d, e, f, i, k, l,
and m.
Terminology for Rooted Trees
(i) What is the subtree
rooted at g?
Solution:
(i) We display the subtree
rooted at g.
Level of vertices and height of trees
• When working with trees, we often want to have rooted trees where the
sub trees at each vertex contain paths of approximately the same length.
• To make this idea precise we need some definitions:
• The level of a vertex v in a rooted tree is the length of the unique path from the
root to this vertex.
• The height of a rooted tree is the maximum of the levels of the vertices.
Level of vertices and height of trees
Example:
(i) Find the level of each vertex
in the tree to the right.
(ii) What is the height of the
tree?
Solution:
(iii)The root a is at level .
Vertices b, j, and k are at level .
Vertices c, e, f, and l are at level .
Vertices d, g, i, m, and n are at level
. Vertex h is at level .
(ii) The height is , since is the
largest level of any vertex.
m-ary Rooted Trees
Definition: 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 = is called a binary tree.
Example: Are the following rooted trees full m-ary trees for
some positive integer m?
Solution:
• T is a full binary tree because each of its internal
vertices has two children.
vertices has three children.
In T each internal vertex has five children,
so T is a full -ary tree.
• T is a full -ary tree because each of its
internal
•
•
T is not a full m-ary tree for any m because some of its
internal vertices have two children and others have
three children.
Balanced m-Ary Trees
Definition: A rooted m-ary tree of height h is balanced if all leaves are at
levels h or h .
Example: Which of the rooted trees shown below is balanced?
Solution: T1 and T3 are balanced, but T2 is not because it has leaves at
levels , , and .
Ordered Rooted Trees
Definition: An ordered rooted tree is a rooted tree where the children of
each internal vertex are ordered.
• We draw ordered rooted trees so that the children of each internal
vertex are shown in order from left to right.
Binary Trees
Definition: A binary tree is an ordered rooted where each internal vertex has at most
two children. If an internal vertex of a binary tree has two children, the first is called
the left child and the second the right child. The tree rooted at the left child of a vertex
is called the left subtree of this vertex, and the tree rooted at the right child of a vertex
is called the right subtree of this vertex.
Example:
Consider the binary tree T.
(i) What are the left and right children of d?
(ii) What are the left and right sub trees of c?
Solution:
(i) The left child of d is f and the right child is g.
(ii) The left and right subtrees of c are displayed in (b) and (c).
Properties of Trees
• A tree with n vertices has n edges.
• A full m-ary tree with i internal vertices has n = mi
vertices.
• A full m-ary tree with:
l
(ii) i
l
(iii) l
(i) n vertices has i = (n − 1)/m internal vertices and
= [(m − 1)n + 1]/m leaves,
n
mi
(
i l
• There are at most leaves in an m-ary tree of
height h.
Binary Search Tree
Definition: A binary tree in which the vertices are labeled with
items so that a label of a vertex is greater than the labels of all
vertices in the left subtree of this vertex and is less than the
labels of all vertices in the right subtree of this vertex.
• Searching for items in a list is one of the most important tasks
that arises in computer science.
• Our primary goal is to implement a searching algorithm that
finds items efficiently when the items are totally ordered. This
can be accomplished through the use of a binary search tree.
Example : Form a binary search tree for the words mathematics,
physics, geography, zoology, meteorology, geology, psychology,
and chemistry (using alphabetical order).

More Related Content

PPT
PPTX
Farhana shaikh webinar_treesindiscretestructure
PDF
trees-and-forest.pdf
PDF
The graph theoretic definition of tree is : it is a finite set of one or more...
PPTX
TreesTreesTreesTreesTreesTreesTrees.pptx
PPTX
Discrete Mathematics Tree
PPT
Lecture in the course of Discrete Mathematics
PDF
07 trees
Farhana shaikh webinar_treesindiscretestructure
trees-and-forest.pdf
The graph theoretic definition of tree is : it is a finite set of one or more...
TreesTreesTreesTreesTreesTreesTrees.pptx
Discrete Mathematics Tree
Lecture in the course of Discrete Mathematics
07 trees

Similar to Notes on trees Introduction and graphs.pptx (20)

PPTX
TREES power point presentation BSIT 1ST YEAR
PPTX
Introduction to tree ds
PPTX
Planer graph, graph coloring, tree and their application
PPT
Ch12 Tree
PPTX
PPTX
discrete mathematics binary%20trees.pptx
PDF
Module - 5_Trees.pdf
PDF
trees.pdf
PPTX
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
PPT
Introduction To Binary Search Trees .ppt
PPTX
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
PPTX
PPTX
Weak 13 Trees, BST update.pptxhjjujjjhhhy
PPT
Lecture 5 trees
PPTX
Lecture 21_Trees - I.pptx
PPTX
non linear data structure -introduction of tree
PPT
Trees
PPTX
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
PPSX
Trees
PDF
Binary tree
TREES power point presentation BSIT 1ST YEAR
Introduction to tree ds
Planer graph, graph coloring, tree and their application
Ch12 Tree
discrete mathematics binary%20trees.pptx
Module - 5_Trees.pdf
trees.pdf
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
Introduction To Binary Search Trees .ppt
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
Weak 13 Trees, BST update.pptxhjjujjjhhhy
Lecture 5 trees
Lecture 21_Trees - I.pptx
non linear data structure -introduction of tree
Trees
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
Trees
Binary tree
Ad

More from fancyatul2024 (6)

PPT
DMaths notes Introduction defination.ppt
PPT
Introduction to and Discrete summary.ppt
PPT
superconductors Introduction and application.ppt
PPTX
Regulator IC using zener and simple diode.pptx
PPTX
Zener Diode Introduction and working .pptx
PPTX
Semiconductor components Atul-Diodes.pptx
DMaths notes Introduction defination.ppt
Introduction to and Discrete summary.ppt
superconductors Introduction and application.ppt
Regulator IC using zener and simple diode.pptx
Zener Diode Introduction and working .pptx
Semiconductor components Atul-Diodes.pptx
Ad

Recently uploaded (20)

PPT
Project quality management in manufacturing
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Digital Logic Computer Design lecture notes
PPTX
additive manufacturing of ss316l using mig welding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
DOCX
573137875-Attendance-Management-System-original
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Project quality management in manufacturing
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Digital Logic Computer Design lecture notes
additive manufacturing of ss316l using mig welding
Model Code of Practice - Construction Work - 21102022 .pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Sustainable Sites - Green Building Construction
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Embodied AI: Ushering in the Next Era of Intelligent Systems
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
573137875-Attendance-Management-System-original
CH1 Production IntroductoryConcepts.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Internet of Things (IOT) - A guide to understanding
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...

Notes on trees Introduction and graphs.pptx

  • 2. Chapter Summary • Introduction to Trees • Applications of Trees • Tree Traversal • Spanning Trees • Minimum Spanning
  • 4. Section Summary • Introduction to Trees • Rooted Trees • Trees as Models • Properties of Trees
  • 5. Tree s Definition: A tree is a connected undirected graph with no simple circuits. Definition: An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices. A tree cannot contain multiple edges or loops. Definition: An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.
  • 6. Trees Example: Which of these graphs are trees? Solution: G and G are trees - both are connected and have no simple circuits. G is not a tree because e, b, a, d, e is a simple circuit,. G is not a tree because it is not connected.
  • 7. FOREST Definition: A forest is a graph that has no simple circuit, but is not connected. Each of the connected components in a forest is a tree.
  • 9. Trees as Models • Trees are used as models in computer science, chemistry, geology, botany, psychology, and many other areas. • Trees were introduced by the mathematician Cayley in in his work counting the number of isomers of saturated hydrocarbons. The two isomers of butane are:. Arthur Cayley ( )
  • 10. Trees as Models • The organization of a computer file system into directories, subdirectories, and files is naturally represented as a tree.
  • 11. Trees as Models • Trees are used to represent the structure of organizations.
  • 12. Applications of Trees •Game Trees Trees can be used to analyze certain types of games such as tic-tac-toe, nim, checkers, and chess.
  • 13. Game Tree for Tic-Tac-Toe
  • 15. Prefix code Definition: A code that has the property that the code of a character is never a prefix of the code of another character. • A prefix code can be represented using a binary tree, where the characters are the labels of the leaves in the tree. • The edges of the tree are labeled so that an edge leading to a left child is assigned a 0 and an edge leading to a right child is assigned a 1. • The bit string used to encode a character is the sequence of labels of the edges in the unique path from the root to the leaf that has this character as its label. • For instance, the tree in Figure 5 represents the encoding of e by 0, a by 10, t by 110, n by 1110, and s by 1111.
  • 16. Decision Trees Definition: A rooted tree where each vertex represents a possible outcome of a decision and the leaves represent the possible solutions of a problem. • Rooted trees can be used to model problems in which a series of decisions leads to a solution. • The possible solutions of the problem correspond to the paths to the leaves of this rooted tree.
  • 17. Example : A decision tree that orders the elements of the list a, b, c.
  • 18. Rooted Trees Definition: A rooted tree is a tree in which one vertex has been designated as the root and every edge is directed away from the root. • An unrooted tree is converted into different rooted trees when different vertices are chosen as the root.
  • 19. Rooted Tree Terminology • Terminology for rooted trees is a mix from botany and genealogy (such as this family tree of the Bernoulli family of mathematicians).
  • 20. Rooted Tree Terminology • If v is a vertex of a rooted tree other than the root, the parent of v is the unique vertex u such that there is a directed edge from u to v. When u is a parent of v, v is called a child of u. Vertices with the same parent are called siblings.
  • 21. Rooted Tree Terminology • The ancestors of a vertex are the vertices in the path from the root to this vertex, excluding the vertex itself and including the root. • The descendants of a vertex v are those vertices that have v as an ancestor. The subtree rooted at u includes all the descendants of u, and all edges that connect between them.
  • 22. Rooted Tree Terminology • A vertex of a rooted tree with no children is called a leaf. Vertices that have children are called internal vertices.
  • 23. Terminology for Rooted Trees Example: In the rooted tree T (with root a): (i) Find the parent of c, the children of g, the siblings of h, the ancestors of e, and the descendants of b. Solution: (i) The parent of c is b. The children of g are h, i, and j. The siblings of h are i and j. The ancestors of e are c, b, and a. The descendants of b are c, d, and e.
  • 24. Terminology for Rooted Trees Example: In the rooted tree T (with root a): (i) Find all internal vertices and all leaves. Solution: (i) The internal vertices are a, b, c, g, h, and j. The leaves are d, e, f, i, k, l, and m.
  • 25. Terminology for Rooted Trees (i) What is the subtree rooted at g? Solution: (i) We display the subtree rooted at g.
  • 26. Level of vertices and height of trees • When working with trees, we often want to have rooted trees where the sub trees at each vertex contain paths of approximately the same length. • To make this idea precise we need some definitions: • The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. • The height of a rooted tree is the maximum of the levels of the vertices.
  • 27. Level of vertices and height of trees Example: (i) Find the level of each vertex in the tree to the right. (ii) What is the height of the tree? Solution: (iii)The root a is at level . Vertices b, j, and k are at level . Vertices c, e, f, and l are at level . Vertices d, g, i, m, and n are at level . Vertex h is at level . (ii) The height is , since is the largest level of any vertex.
  • 28. m-ary Rooted Trees Definition: 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 = is called a binary tree. Example: Are the following rooted trees full m-ary trees for some positive integer m?
  • 29. Solution: • T is a full binary tree because each of its internal vertices has two children. vertices has three children. In T each internal vertex has five children, so T is a full -ary tree. • T is a full -ary tree because each of its internal • • T is not a full m-ary tree for any m because some of its internal vertices have two children and others have three children.
  • 30. Balanced m-Ary Trees Definition: A rooted m-ary tree of height h is balanced if all leaves are at levels h or h . Example: Which of the rooted trees shown below is balanced? Solution: T1 and T3 are balanced, but T2 is not because it has leaves at levels , , and .
  • 31. Ordered Rooted Trees Definition: An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. • We draw ordered rooted trees so that the children of each internal vertex are shown in order from left to right.
  • 32. Binary Trees Definition: A binary tree is an ordered rooted where each internal vertex has at most two children. If an internal vertex of a binary tree has two children, the first is called the left child and the second the right child. The tree rooted at the left child of a vertex is called the left subtree of this vertex, and the tree rooted at the right child of a vertex is called the right subtree of this vertex.
  • 33. Example: Consider the binary tree T. (i) What are the left and right children of d? (ii) What are the left and right sub trees of c? Solution: (i) The left child of d is f and the right child is g. (ii) The left and right subtrees of c are displayed in (b) and (c).
  • 34. Properties of Trees • A tree with n vertices has n edges. • A full m-ary tree with i internal vertices has n = mi vertices. • A full m-ary tree with: l (ii) i l (iii) l (i) n vertices has i = (n − 1)/m internal vertices and = [(m − 1)n + 1]/m leaves, n mi ( i l • There are at most leaves in an m-ary tree of height h.
  • 35. Binary Search Tree Definition: A binary tree in which the vertices are labeled with items so that a label of a vertex is greater than the labels of all vertices in the left subtree of this vertex and is less than the labels of all vertices in the right subtree of this vertex. • Searching for items in a list is one of the most important tasks that arises in computer science. • Our primary goal is to implement a searching algorithm that finds items efficiently when the items are totally ordered. This can be accomplished through the use of a binary search tree.
  • 36. Example : Form a binary search tree for the words mathematics, physics, geography, zoology, meteorology, geology, psychology, and chemistry (using alphabetical order).