SlideShare a Scribd company logo
Trees
module 3
General Trees
• A graph which has no cycle is called an acyclic graph. A tree
is an acyclic graph or graph having no cycles.
• A tree or general trees is defined as a non-empty finite set of
elements called vertices or nodes having the property that
each node can have minimum degree 1 and maximum
degree n. It can be partitioned into n+1 disjoint subsets such
that the first subset contains the root of the tree and
remaining n subsets includes the elements of the n subtree.
TreesTreesTreesTreesTreesTreesTrees.pptx
Directed Trees:
• A directed tree is an acyclic directed graph. It has one node
with indegree 0, while all other nodes have indegree 1
• The node which has outdegree 0 is called an external node or a
terminal node or a leaf. The nodes which have outdegree greater
than or equal to one are called internal node.
Ordered Trees
• If in a tree at each level, an ordering is defined, then such a tree is
called an ordered tree.
Properties of Trees:
1.There is only one path between each pair of vertices of a
tree.
2.If a graph G there is one and only one path between each
pair of vertices G is a tree.
3.A tree T with n vertices has n-1 edges.
4.A graph is a tree if and only if it a minimal connected.
Rooted Trees
• If a directed tree has exactly one node or vertex called root
whose incoming degrees is 0 and all other vertices have
incoming degree one, then the tree is called rooted tree.
• Note: 1. A tree with no nodes is a rooted tree (the empty tree)
2. A single node with no children is a rooted tree.
Path length of a Vertex:
• The path length of a vertex in a rooted tree is defined to be
the number of edges in the path from the root to the vertex.
Binary Trees
• If the outdegree of every node is less than or equal to 2, in a
directed tree than the tree is called a binary tree. A tree
consisting of the nodes (empty tree) is also a binary tree.
• Root: A binary tree has a unique node called the root of the
tree.
• Left Child: The node to the left of the root is called its left
child.
• Right Child: The node to the right of the root is called its
right child.
Binary tree
• Parent: A node having a left child or right child or both are called
the parent of the nodes.
• Siblings: Two nodes having the same parent are called siblings.
• Leaf: A node with no children is called a leaf. The number of leaves
in a binary tree can vary from one (minimum) to half the number of
vertices (maximum) in a tree.
• Descendant: A node is called descendant of another node if it is the
child of the node or child of some other descendant of that node. All
the nodes in the tree are descendants of the root.
• Left Subtree: The subtree whose root is the left child of some node
is called the left subtree of that node.
(i) The node A is the root node.
(ii) The nodes G, H, I, L, M, N, O are leaves.
(iii) Nodes Parent
B, C A
D, E B
F C
G, H D
I, J E
K F
L, M J
N, O K
Right Subtree: The subtree whose root is the right
child of some node is called the right subtree of that
node.
• Level of a Node: The level of a node is its distance from the root. The level of root is defined
as zero. The level of all other nodes is one more than its parent node. The maximum number
of nodes at any level N is 2N
.
• Depth or Height of a tree: The depth or height of a tree is defined as the maximum number
of nodes in a branch of a tree. This is more than the maximum level of the tree, i.e., the depth
of root is one. The maximum number of nodes in a binary tree of depth d is 2d
-1, where d 1.
≥
• External Nodes: The nodes which have no children are called external nodes or terminal
nodes.
• Internal Nodes: The nodes which have one or more than one children are called internal
nodes or non-terminal nodes.
• Level of a Node: The level of a node is its distance from the root. The level of root is defined
as zero. The level of all other nodes is one more than its parent node. The maximum number
of nodes at any level N is 2N
.
• Depth or Height of a tree: The depth or height of a tree is defined as the maximum number
of nodes in a branch of a tree. This is more than the maximum level of the tree, i.e., the depth
of root is one. The maximum number of nodes in a binary tree of depth d is 2d
-1, where d 1.
≥
• External Nodes: The nodes which have no children are called external nodes or terminal
nodes.
• Internal Nodes: The nodes which have one or more than one children are called internal
nodes or non-terminal nodes.
Binary Expression Trees:
• An algebraic expression can be conveniently expressed by
its expression tree. An expression having binary operators
can be decomposed into<left operand or expression>
(operator) <right operand or expression>
• Depending upon precedence of evaluation.
• The expression tree is a binary tree whose root contains the
operator and whose left subtree contains the left
expression, and right subtree contains the right expression.
• (a+b)*(d/c)
Complete Binary Tree
• Complete binary tree is a binary tree if it is all levels, except
possibly the last, have the maximum number of possible
nodes as for left as possible. The depth of the complete
binary tree having n nodes is log2 n+1.
Full Binary Tree:
• Full binary tree is a binary tree in which all the leaves are on
the same level and every non-leaf node has two children.
Tree traversal
• Preorder: Visit root, traverse left, traverse right
• Inorder: Traverse left, visit root, traverse right
• Postorder: Traverse left, traverse right, visit root
• Preorder Traversal: The preorder traversal of a binary tree
is a recursive process. The preorder traversal of a tree is
• Visit the root of the tree.
• Traverse the left subtree in preorder.
• Traverse the right subtree in preorder.
Preor
der
1 2 3 4 5 6 7 8 9 10 11
Postorder Traversal
The postorder traversal of a binary tree is a recursive process. The postorder traversal of a tree is
•Traverse the left subtree in postorder.
•Traverse the right subtree in postorder.
•Visit the root of the tree.
•Postorder 3 5 4 2 7 10 9 11 8 6 1
. Inorder Traversal
The inorder traversal of a binary tree is a recursive process.
The inorder traversal of a tree is
•Traverse in inorder the left subtree.
•Visit the root of the tree.
•Traverse in inorder the right subtree.
Inorde
r
3 2 5 4 1 7 6 9 10 8 11
Draw the unique binary tree when the inorder
and preorder traversal is given as follows:
Inorde
r
B A D C F E J H K G I
Preord
er
A B C D E F G H J K I
• in = {4, 8, 2, 5, 1, 6, 3, 7}
post = {8, 4, 5, 2, 6, 7, 3, 1}
• Output: Root of below tree
• 1
/ 
2 3
/  / 
4 5 6 7

8
Spanning tree
• A spanning tree of a connected undirected graph G is a tree that
minimally includes all of the vertices of G
• . A graph may have many spanning trees.
Minimum Spanning Tree
• A spanning tree with assigned weight less than or equal to the weight
of every possible spanning tree of a weighted, connected and
undirected graph G , it is called minimum spanning tree (MST).
• The weight of a spanning tree is the sum of all the weights assigned to
each edge of the spanning tree.
Kruskal's Algorithm
• Kruskal's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected
weighted graph. It finds a tree of that graph which includes every vertex and the total weight of all
the edges in the tree is less than or equal to every possible spanning tree.
• Algorithm
• Step 1 − Arrange all the edges of the given graph G(V,E) in ascending order as per their edge weight.
• Step 2 − Choose the smallest weighted edge from the graph and check if it forms a cycle with the
spanning tree formed so far.
• Step 3 − If there is no cycle, include this edge to the spanning tree else discard it.
• Step 4 − Repeat Step 2 and Step 3 until (V−1)
• number of edges are left in the spanning tree.
Edge No.
Vertex
Pair
Edge
Weight
E4 (b, c) 1
E7 (c, d) 2
E8 (d, e) 3
E5 (b, e) 4
E6 (b, f) 5
E2 (a, c) 9
E3 (a, d) 13
E9 (d, f) 14
E1 (a, b) 20
TreesTreesTreesTreesTreesTreesTrees.pptx
TreesTreesTreesTreesTreesTreesTrees.pptx
TreesTreesTreesTreesTreesTreesTrees.pptx

More Related Content

PDF
Module - 5_Trees.pdf
AnuradhaJadiya1
 
PPTX
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
KALPANAC20
 
PPTX
Tree Basic concepts of Tree in Data Structure
Manoj PAtil
 
PPTX
Tree
knightofheart
 
PPTX
Introduction to Tree_Data Structure.pptx
PoojariniMitra1
 
PPTX
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DRCARIBOU
 
PPTX
Introduction to tree ds
Viji B
 
PDF
unit-2-dsa-tree-2024-1 (1) (1).pdf data structure
SanketDawbhat
 
Module - 5_Trees.pdf
AnuradhaJadiya1
 
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
KALPANAC20
 
Tree Basic concepts of Tree in Data Structure
Manoj PAtil
 
Introduction to Tree_Data Structure.pptx
PoojariniMitra1
 
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DRCARIBOU
 
Introduction to tree ds
Viji B
 
unit-2-dsa-tree-2024-1 (1) (1).pdf data structure
SanketDawbhat
 

Similar to TreesTreesTreesTreesTreesTreesTrees.pptx (20)

PPTX
Data structures 3
Parthipan Parthi
 
PPTX
Tree.pptx
worldchannel
 
PPTX
Lecture 9: Binary tree basics
Vivek Bhargav
 
PPTX
Farhana shaikh webinar_treesindiscretestructure
Farhana Shaikh
 
PPTX
Unit 3 trees
LavanyaJ28
 
PPT
Lecture 5 trees
Victor Palmar
 
PPTX
TREES34.pptx
BharathChalla5
 
PPTX
Lecture 9 (DS) - Tree, Tree Traversal.pptx
itxdevilmehar
 
PPT
BINARY SEARCH TREE
ER Punit Jain
 
PPTX
Lecture 2-Trees in Data Structure Complete Lecture Slide
KrishnenduRarhi
 
PPTX
Search tree,Tree and binary tree and heap tree
zia eagle
 
PPTX
DISCRETE MATHEMATICS POWRPOINT PRESENTATION ON COMBINATIONS
NabeelRehman21
 
PPTX
DSA-Unit-2.pptx
SeethaDinesh
 
PPTX
unit-2-data structure and algorithms-tree-2024-1.pptx
pritimalkhede
 
PDF
unit-2-dsa-tree introduction of tree and terninology
sayalijscoe2
 
PPT
358 33 powerpoint-slides_10-trees_chapter-10
sumitbardhan
 
PPTX
Discrete Mathematics Tree
Masud Parvaze
 
PPT
Unit III.ppt
sherrilsiddhardh
 
PPTX
Tree all information about tree concept are available .
FaizanAhmad293255
 
Data structures 3
Parthipan Parthi
 
Tree.pptx
worldchannel
 
Lecture 9: Binary tree basics
Vivek Bhargav
 
Farhana shaikh webinar_treesindiscretestructure
Farhana Shaikh
 
Unit 3 trees
LavanyaJ28
 
Lecture 5 trees
Victor Palmar
 
TREES34.pptx
BharathChalla5
 
Lecture 9 (DS) - Tree, Tree Traversal.pptx
itxdevilmehar
 
BINARY SEARCH TREE
ER Punit Jain
 
Lecture 2-Trees in Data Structure Complete Lecture Slide
KrishnenduRarhi
 
Search tree,Tree and binary tree and heap tree
zia eagle
 
DISCRETE MATHEMATICS POWRPOINT PRESENTATION ON COMBINATIONS
NabeelRehman21
 
DSA-Unit-2.pptx
SeethaDinesh
 
unit-2-data structure and algorithms-tree-2024-1.pptx
pritimalkhede
 
unit-2-dsa-tree introduction of tree and terninology
sayalijscoe2
 
358 33 powerpoint-slides_10-trees_chapter-10
sumitbardhan
 
Discrete Mathematics Tree
Masud Parvaze
 
Unit III.ppt
sherrilsiddhardh
 
Tree all information about tree concept are available .
FaizanAhmad293255
 
Ad

Recently uploaded (20)

PPTX
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PDF
Queuing formulas to evaluate throughputs and servers
gptshubham
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PDF
Software Testing Tools - names and explanation
shruti533256
 
PPTX
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
Queuing formulas to evaluate throughputs and servers
gptshubham
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
Software Testing Tools - names and explanation
shruti533256
 
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
Ppt for engineering students application on field effect
lakshmi.ec
 
Ad

TreesTreesTreesTreesTreesTreesTrees.pptx

  • 2. General Trees • A graph which has no cycle is called an acyclic graph. A tree is an acyclic graph or graph having no cycles. • A tree or general trees is defined as a non-empty finite set of elements called vertices or nodes having the property that each node can have minimum degree 1 and maximum degree n. It can be partitioned into n+1 disjoint subsets such that the first subset contains the root of the tree and remaining n subsets includes the elements of the n subtree.
  • 4. Directed Trees: • A directed tree is an acyclic directed graph. It has one node with indegree 0, while all other nodes have indegree 1
  • 5. • The node which has outdegree 0 is called an external node or a terminal node or a leaf. The nodes which have outdegree greater than or equal to one are called internal node.
  • 6. Ordered Trees • If in a tree at each level, an ordering is defined, then such a tree is called an ordered tree.
  • 7. Properties of Trees: 1.There is only one path between each pair of vertices of a tree. 2.If a graph G there is one and only one path between each pair of vertices G is a tree. 3.A tree T with n vertices has n-1 edges. 4.A graph is a tree if and only if it a minimal connected.
  • 8. Rooted Trees • If a directed tree has exactly one node or vertex called root whose incoming degrees is 0 and all other vertices have incoming degree one, then the tree is called rooted tree. • Note: 1. A tree with no nodes is a rooted tree (the empty tree) 2. A single node with no children is a rooted tree.
  • 9. Path length of a Vertex: • The path length of a vertex in a rooted tree is defined to be the number of edges in the path from the root to the vertex.
  • 10. Binary Trees • If the outdegree of every node is less than or equal to 2, in a directed tree than the tree is called a binary tree. A tree consisting of the nodes (empty tree) is also a binary tree. • Root: A binary tree has a unique node called the root of the tree. • Left Child: The node to the left of the root is called its left child. • Right Child: The node to the right of the root is called its right child.
  • 11. Binary tree • Parent: A node having a left child or right child or both are called the parent of the nodes. • Siblings: Two nodes having the same parent are called siblings. • Leaf: A node with no children is called a leaf. The number of leaves in a binary tree can vary from one (minimum) to half the number of vertices (maximum) in a tree. • Descendant: A node is called descendant of another node if it is the child of the node or child of some other descendant of that node. All the nodes in the tree are descendants of the root. • Left Subtree: The subtree whose root is the left child of some node is called the left subtree of that node.
  • 12. (i) The node A is the root node. (ii) The nodes G, H, I, L, M, N, O are leaves. (iii) Nodes Parent B, C A D, E B F C G, H D I, J E K F L, M J N, O K Right Subtree: The subtree whose root is the right child of some node is called the right subtree of that node.
  • 13. • Level of a Node: The level of a node is its distance from the root. The level of root is defined as zero. The level of all other nodes is one more than its parent node. The maximum number of nodes at any level N is 2N . • Depth or Height of a tree: The depth or height of a tree is defined as the maximum number of nodes in a branch of a tree. This is more than the maximum level of the tree, i.e., the depth of root is one. The maximum number of nodes in a binary tree of depth d is 2d -1, where d 1. ≥ • External Nodes: The nodes which have no children are called external nodes or terminal nodes. • Internal Nodes: The nodes which have one or more than one children are called internal nodes or non-terminal nodes. • Level of a Node: The level of a node is its distance from the root. The level of root is defined as zero. The level of all other nodes is one more than its parent node. The maximum number of nodes at any level N is 2N . • Depth or Height of a tree: The depth or height of a tree is defined as the maximum number of nodes in a branch of a tree. This is more than the maximum level of the tree, i.e., the depth of root is one. The maximum number of nodes in a binary tree of depth d is 2d -1, where d 1. ≥ • External Nodes: The nodes which have no children are called external nodes or terminal nodes. • Internal Nodes: The nodes which have one or more than one children are called internal nodes or non-terminal nodes.
  • 14. Binary Expression Trees: • An algebraic expression can be conveniently expressed by its expression tree. An expression having binary operators can be decomposed into<left operand or expression> (operator) <right operand or expression> • Depending upon precedence of evaluation. • The expression tree is a binary tree whose root contains the operator and whose left subtree contains the left expression, and right subtree contains the right expression.
  • 16. Complete Binary Tree • Complete binary tree is a binary tree if it is all levels, except possibly the last, have the maximum number of possible nodes as for left as possible. The depth of the complete binary tree having n nodes is log2 n+1.
  • 17. Full Binary Tree: • Full binary tree is a binary tree in which all the leaves are on the same level and every non-leaf node has two children.
  • 18. Tree traversal • Preorder: Visit root, traverse left, traverse right • Inorder: Traverse left, visit root, traverse right • Postorder: Traverse left, traverse right, visit root • Preorder Traversal: The preorder traversal of a binary tree is a recursive process. The preorder traversal of a tree is • Visit the root of the tree. • Traverse the left subtree in preorder. • Traverse the right subtree in preorder.
  • 19. Preor der 1 2 3 4 5 6 7 8 9 10 11
  • 20. Postorder Traversal The postorder traversal of a binary tree is a recursive process. The postorder traversal of a tree is •Traverse the left subtree in postorder. •Traverse the right subtree in postorder. •Visit the root of the tree. •Postorder 3 5 4 2 7 10 9 11 8 6 1
  • 21. . Inorder Traversal The inorder traversal of a binary tree is a recursive process. The inorder traversal of a tree is •Traverse in inorder the left subtree. •Visit the root of the tree. •Traverse in inorder the right subtree. Inorde r 3 2 5 4 1 7 6 9 10 8 11
  • 22. Draw the unique binary tree when the inorder and preorder traversal is given as follows: Inorde r B A D C F E J H K G I Preord er A B C D E F G H J K I
  • 23. • in = {4, 8, 2, 5, 1, 6, 3, 7} post = {8, 4, 5, 2, 6, 7, 3, 1} • Output: Root of below tree • 1 / 2 3 / / 4 5 6 7 8
  • 24. Spanning tree • A spanning tree of a connected undirected graph G is a tree that minimally includes all of the vertices of G • . A graph may have many spanning trees.
  • 25. Minimum Spanning Tree • A spanning tree with assigned weight less than or equal to the weight of every possible spanning tree of a weighted, connected and undirected graph G , it is called minimum spanning tree (MST). • The weight of a spanning tree is the sum of all the weights assigned to each edge of the spanning tree.
  • 26. Kruskal's Algorithm • Kruskal's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected weighted graph. It finds a tree of that graph which includes every vertex and the total weight of all the edges in the tree is less than or equal to every possible spanning tree. • Algorithm • Step 1 − Arrange all the edges of the given graph G(V,E) in ascending order as per their edge weight. • Step 2 − Choose the smallest weighted edge from the graph and check if it forms a cycle with the spanning tree formed so far. • Step 3 − If there is no cycle, include this edge to the spanning tree else discard it. • Step 4 − Repeat Step 2 and Step 3 until (V−1) • number of edges are left in the spanning tree.
  • 27. Edge No. Vertex Pair Edge Weight E4 (b, c) 1 E7 (c, d) 2 E8 (d, e) 3 E5 (b, e) 4 E6 (b, f) 5 E2 (a, c) 9 E3 (a, d) 13 E9 (d, f) 14 E1 (a, b) 20