SlideShare a Scribd company logo
Tree
 basic operations of a tree:
• tree traversals
• insert node
• delete node
• searching
 A tree is a collection of nodes and edges
 A tree has only one root
 Trees are hierarchical:
Parent-child relationship between two nodes
Tree
E
R
T
E
L
P
M
E
A
S
A
root
Leaves or terminal
nodes
Child (of
root)
Depth of T: 2
Tree height: 4
Level
0
1
3
2
A tree in which no node
can have more than two
children
Binary Trees
A General Tree & A Binary Tree
Balanced Binary Trees
A binary tree is balanced if the heights of any node’s two subtrees differ
by no more than 1
Complete binary trees are balanced
Full binary trees are complete and balanced
B = HL - HR
Example:
2-1=1
1-1=0
3-2=1 1-2=-1
A
B
A
B
A
B C
A
D E
Balance
Balance
Balance
Balance
Q: Write the following operations as binary tree and determine the
(tree Depth, tree height, number of levels).
A. 2+3
Example of tree application:
•Represent algebraic formulas
2 3
+
1 Tree depth
2 Tree height
1 Number of levels
B. (6/2) * (20-4)
/ -
*
6 2 6 2
2 Tree depth
3 Tree height
2 Number of levels
Tree traversal
Type of Traversal
•Inorder traversal
•Preorder traversal
•Postorder traversal
 Inorder traversal
 Recursively print out all data in the left subtree
 Print the data at the root
 Recursively print out all data in the right subtree
 Pre-order traversal
 Print the data at the root
 Recursively print out all data in the left subtree
 Recursively print out all data in the right subtree
 Postorder traversal
 Recursively print out all data in the left subtree
 Recursively print out all data in the right subtree
 Print the data at the root
Traverse the following binary tree using the three types of
tree traversal
a. Preorder (NLR)
6, 2, 1, 4, 3, 7, 10 , 9, 11
b. Postorder (LRN)
1, 3, 4, 2, 9, 11 ,10, 7, 6
c. Inorder (LNR)
1, 2, 3, 4, 6, 7, 9, 10, 11
2 7
6
1 4
9 11
3
10

More Related Content

PPTX
Introduction to Tree_Data Structure.pptx
PPT
data_structures_and_applications_-_module-4.ppt
PPT
Tree 11.ppt
PPTX
unit 4 for trees data structure notes it is
PPTX
Tree all information about tree concept are available .
PPT
Data Structures 4
PPTX
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
PPTX
tree-160731205832.pptx
Introduction to Tree_Data Structure.pptx
data_structures_and_applications_-_module-4.ppt
Tree 11.ppt
unit 4 for trees data structure notes it is
Tree all information about tree concept are available .
Data Structures 4
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
tree-160731205832.pptx

Similar to tutorial-tree (3).ppt (20)

PPT
Trees
PDF
Module - 5_Trees.pdf
PPTX
Unit 6 tree
PPTX
Lecture 8 data structures and algorithms
PPTX
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
PPTX
PPTX
Unit 3 trees
PPTX
Bsc cs ii dfs u-3 tree and graph
PPTX
Bca ii dfs u-3 tree and graph
PPT
Data Structure: TREES
PPT
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
PPT
Tree_Traversals.pptmmmmmmmmmmmmmmmmmmmmm
PPT
358 33 powerpoint-slides_10-trees_chapter-10
PPTX
Balance tree. Short overview
PPT
Data Structures 5
PPTX
Mca iii dfs u-4 tree and graph
PPT
Data Structure and Algorithms Binary Tree
PPTX
Tree.pptx
PPTX
DSA-Unit-2.pptx
Trees
Module - 5_Trees.pdf
Unit 6 tree
Lecture 8 data structures and algorithms
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
Unit 3 trees
Bsc cs ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
Data Structure: TREES
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptmmmmmmmmmmmmmmmmmmmmm
358 33 powerpoint-slides_10-trees_chapter-10
Balance tree. Short overview
Data Structures 5
Mca iii dfs u-4 tree and graph
Data Structure and Algorithms Binary Tree
Tree.pptx
DSA-Unit-2.pptx
Ad

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Complications of Minimal Access Surgery at WLH
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Trump Administration's workforce development strategy
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Cell Types and Its function , kingdom of life
STATICS OF THE RIGID BODIES Hibbelers.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A systematic review of self-coping strategies used by university students to ...
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Pharma ospi slides which help in ospi learning
Complications of Minimal Access Surgery at WLH
Weekly quiz Compilation Jan -July 25.pdf
O7-L3 Supply Chain Operations - ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Microbial diseases, their pathogenesis and prophylaxis
Trump Administration's workforce development strategy
Microbial disease of the cardiovascular and lymphatic systems
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Ad

tutorial-tree (3).ppt

  • 2.  basic operations of a tree: • tree traversals • insert node • delete node • searching  A tree is a collection of nodes and edges  A tree has only one root  Trees are hierarchical: Parent-child relationship between two nodes Tree
  • 3. E R T E L P M E A S A root Leaves or terminal nodes Child (of root) Depth of T: 2 Tree height: 4 Level 0 1 3 2
  • 4. A tree in which no node can have more than two children Binary Trees
  • 5. A General Tree & A Binary Tree
  • 6. Balanced Binary Trees A binary tree is balanced if the heights of any node’s two subtrees differ by no more than 1 Complete binary trees are balanced Full binary trees are complete and balanced B = HL - HR
  • 7. Example: 2-1=1 1-1=0 3-2=1 1-2=-1 A B A B A B C A D E Balance Balance Balance Balance
  • 8. Q: Write the following operations as binary tree and determine the (tree Depth, tree height, number of levels). A. 2+3 Example of tree application: •Represent algebraic formulas 2 3 + 1 Tree depth 2 Tree height 1 Number of levels
  • 9. B. (6/2) * (20-4) / - * 6 2 6 2 2 Tree depth 3 Tree height 2 Number of levels
  • 10. Tree traversal Type of Traversal •Inorder traversal •Preorder traversal •Postorder traversal
  • 11.  Inorder traversal  Recursively print out all data in the left subtree  Print the data at the root  Recursively print out all data in the right subtree  Pre-order traversal  Print the data at the root  Recursively print out all data in the left subtree  Recursively print out all data in the right subtree  Postorder traversal  Recursively print out all data in the left subtree  Recursively print out all data in the right subtree  Print the data at the root
  • 12. Traverse the following binary tree using the three types of tree traversal a. Preorder (NLR) 6, 2, 1, 4, 3, 7, 10 , 9, 11 b. Postorder (LRN) 1, 3, 4, 2, 9, 11 ,10, 7, 6 c. Inorder (LNR) 1, 2, 3, 4, 6, 7, 9, 10, 11 2 7 6 1 4 9 11 3 10