SlideShare a Scribd company logo
1 of 10
Download to read offline
Tree Traversals
Ms. Mary Jacob
Assistant Professor
Kristu Jayanti College (Autonomous),Bangalore
1.Tree- Definition
2.Binary tree
3.Binary tree - Properties
4.Traversals
CONTENTS
A Tree is a data structure that emulates a hierarchical tree structure with a set of linked
nodes.
It is a data structure accessed beginning at the root node. Each node is either a leaf or an
internal node. An internal node has one or more child nodes and is called the parent of its
child nodes. All children of the same node are siblings. Contrary to a physical tree, the root
is usually depicted at the top of the structure, and the leaves are depicted at the bottom.
Ø A Tree is a data structure that emulates a hierarchical tree structure with a set of linked
nodes.
Ø It is a data structure accessed beginning at the root node. Each node is either a leaf or an
internal node.
Ø An internal node has one or more child nodes and is called the parent of its child nodes.
All children of the same node are siblings.
Tree- Definition
A Tree is a data structure that emulates a hierarchical tree
structure with a set of linked nodes.
It is a data structure accessed beginning at the root node. Each
node is either a leaf or an internal node. An internal node has
one or more child nodes and is called the parent of its child
nodes. All children of the same node are siblings. Contrary to a
physical tree, the root is usually depicted at the top of the
structure, and the leaves are depicted at the bottom.
Ø Root: node without parent (A)
Ø Internal node: node with at least one child (A, B, C, F)
Ø External node: a kind of leaf node without children (E, I, J, K, G, H, D)
Ø Ancestors of a node: parent, grandparent, grand-grandparent, etc
Ø Depth of a node: number of ancestors
Ø Height of a tree: maximum depth of any node (3)
Ø Descendant of a node: child, grandchild, grand-grandchild, etc
Ø Degree of an element: no. of children it has
Ø Sub tree: tree consisting of a node and its descendants
Ø Path: traversal from node to node along the edges that results in
a sequence
Ø Root: node at the top of the tree
Ø Parent: any node, except root has exactly one edge running upward to
another node. The node above it is called parent.
Tree Terminologies
A Tree is a data structure that emulates a hierarchical tree structure with a set of linked
nodes.
It is a data structure accessed beginning at the root node. Each node is either a leaf or an
internal node. An internal node has one or more child nodes and is called the parent of its
child nodes. All children of the same node are siblings. Contrary to a physical tree, the root
is usually depicted at the top of the structure, and the leaves are depicted at the bottom.
Ø Child: any node may have one or more lines running downward
to other nodes. Nodes below are children.
Ø Leaf: a node that has no children
Ø Sub tree: any node can be considered to be the root of a subtree,
which consists of its children and its children's children and so
on.
Ø Visiting: a node is visited when program control arrives at the
node, usually for processing.
Ø Traversing: to traverse a tree means to visit all the nodes in
some specified order.
Ø Levels: the level of a particular node refers to how many
generations the node is from the root. Root is assumed to be
level 0.
Tree Terminologies
A Tree is a data structure that emulates a hierarchical tree structure with a set of linked
nodes.
It is a data structure accessed beginning at the root node. Each node is either a leaf or an
internal node. An internal node has one or more child nodes and is called the parent of its
child nodes. All children of the same node are siblings. Contrary to a physical tree, the root
is usually depicted at the top of the structure, and the leaves are depicted at the bottom.
Ø Binary tree is a set of finite nodes which is either empty or consists of one or more nodes in
which each node has at most two disjoint binary sub trees called left sub tree or right sub tree
respectively.
Ø There may be a zero degree node or a one degree node or a two degree node.
Binary Tree
A Tree is a data structure that emulates a hierarchical tree structure with a set of linked
nodes.
It is a data structure accessed beginning at the root node. Each node is either a leaf or an
internal node. An internal node has one or more child nodes and is called the parent of its
child nodes. All children of the same node are siblings. Contrary to a physical tree, the root
is usually depicted at the top of the structure, and the leaves are depicted at the bottom.
Binary Tree - Properties
Ø The maximum number of nodes at a level I of binary tree is 2I where I>=0.
Ø If h = height of a binary tree,
max number of nodes possible in a binary tree of height h is 2h-1
min number of nodes possible in a binary tree of height h is h
Ø For any non empty tree, number of terminal or leaf nodes is equal to number of non
terminal nodes(internal nodes) +1.
Ø For any non empty binary tree, if ‘n’ is the number of nodes and ‘e’ is the number of
edges, then n=e+1;
Ø Total number of binary trees possible with n nodes is 1/(n+1)2ncn
Ø A binary tree with height h and 2h + 1 - 1 nodes (or 2h leaves) is called a full binary
tree
A Tree is a data structure that emulates a hierarchical tree structure with a set of linked
nodes.
It is a data structure accessed beginning at the root node. Each node is either a leaf or an
internal node. An internal node has one or more child nodes and is called the parent of its
child nodes. All children of the same node are siblings. Contrary to a physical tree, the root
is usually depicted at the top of the structure, and the leaves are depicted at the bottom.
Traversals of a Binary Tree
The tree can be traversed in inorder, preorder and postorder methods.
PREORDER TRAVERSAL:
Ø Process the root R.
Ø Traverse the left sub tree of R in preorder.
Ø Traverse the right sub tree of R in preorder.
INORDER TRAVERSAL:
Ø Traverse the left sub tree of R in inorder.
Ø Process the root R.
Ø Traverse the right sub tree of R in inorder.
POSTORDER TRAVERSAL :
Ø Traverse the left sub tree of R in postorder.
Ø Traverse the right sub tree of R in postorder.
Ø Process the root R.
The order in which each node in the tree is traversed is as follows,
INORDER TRAVERSAL:10,15 ,16 ,32 ,33,34,87
PREORDER TRAVERSAL :32 ,16,10,15,34,33,87
POSTORDER TRAVERSAL :15, 10, 16, 33, 87, 34, 32
Traversals of a Binary Tree -Example
The order in which each node in the tree is traversed is as follows,
INORDER TRAVERSAL:10,15 ,16 ,32 ,33,34,87
PREORDER TRAVERSAL :32 ,16,10,15,34,33,87
POSTORDER TRAVERSAL :15, 10, 16, 33, 87, 34, 32
Thank You

More Related Content

Similar to tree traversals.pdf

Similar to tree traversals.pdf (20)

Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
 
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
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
 
Tree data structure
Tree data structureTree data structure
Tree data structure
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Tree
TreeTree
Tree
 
Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics Tree
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
tree Data Structures in python Traversals.pptx
tree Data Structures in python Traversals.pptxtree Data Structures in python Traversals.pptx
tree Data Structures in python Traversals.pptx
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Trees
TreesTrees
Trees
 
Tree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data StructureTree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data Structure
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 
Discrete Mathematics - Trees
Discrete Mathematics - TreesDiscrete Mathematics - Trees
Discrete Mathematics - Trees
 
Lecture 5 trees
Lecture 5 treesLecture 5 trees
Lecture 5 trees
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 

More from MaryJacob24

Unit 1-Introduction to Data Structures-BCA.pdf
Unit 1-Introduction to Data Structures-BCA.pdfUnit 1-Introduction to Data Structures-BCA.pdf
Unit 1-Introduction to Data Structures-BCA.pdfMaryJacob24
 
Unit 2-Data Modeling.pdf
Unit 2-Data Modeling.pdfUnit 2-Data Modeling.pdf
Unit 2-Data Modeling.pdfMaryJacob24
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdfMaryJacob24
 
Unit 4- Dynamic Programming.pdf
Unit 4- Dynamic Programming.pdfUnit 4- Dynamic Programming.pdf
Unit 4- Dynamic Programming.pdfMaryJacob24
 
Unit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxUnit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxMaryJacob24
 
Linked List-Types.pdf
Linked List-Types.pdfLinked List-Types.pdf
Linked List-Types.pdfMaryJacob24
 
Unit 5- Cloud Applications.pdf
Unit 5- Cloud Applications.pdfUnit 5- Cloud Applications.pdf
Unit 5- Cloud Applications.pdfMaryJacob24
 
Simplification of Circuits.pdf
Simplification of Circuits.pdfSimplification of Circuits.pdf
Simplification of Circuits.pdfMaryJacob24
 
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...MaryJacob24
 
Algorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfAlgorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfMaryJacob24
 
Data Structures & Recursion-Introduction.pdf
Data Structures & Recursion-Introduction.pdfData Structures & Recursion-Introduction.pdf
Data Structures & Recursion-Introduction.pdfMaryJacob24
 
Unit 3 - Greedy Method
Unit 3  - Greedy MethodUnit 3  - Greedy Method
Unit 3 - Greedy MethodMaryJacob24
 
Unit 3 greedy method
Unit 3  greedy methodUnit 3  greedy method
Unit 3 greedy methodMaryJacob24
 
Graph Traversals
Graph TraversalsGraph Traversals
Graph TraversalsMaryJacob24
 

More from MaryJacob24 (15)

Unit 1-Introduction to Data Structures-BCA.pdf
Unit 1-Introduction to Data Structures-BCA.pdfUnit 1-Introduction to Data Structures-BCA.pdf
Unit 1-Introduction to Data Structures-BCA.pdf
 
Unit 2-Data Modeling.pdf
Unit 2-Data Modeling.pdfUnit 2-Data Modeling.pdf
Unit 2-Data Modeling.pdf
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
Unit 4- Dynamic Programming.pdf
Unit 4- Dynamic Programming.pdfUnit 4- Dynamic Programming.pdf
Unit 4- Dynamic Programming.pdf
 
Unit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxUnit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptx
 
Linked List-Types.pdf
Linked List-Types.pdfLinked List-Types.pdf
Linked List-Types.pdf
 
Unit 5- Cloud Applications.pdf
Unit 5- Cloud Applications.pdfUnit 5- Cloud Applications.pdf
Unit 5- Cloud Applications.pdf
 
Simplification of Circuits.pdf
Simplification of Circuits.pdfSimplification of Circuits.pdf
Simplification of Circuits.pdf
 
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
 
Algorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfAlgorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdf
 
Data Structures & Recursion-Introduction.pdf
Data Structures & Recursion-Introduction.pdfData Structures & Recursion-Introduction.pdf
Data Structures & Recursion-Introduction.pdf
 
quick sort.pdf
quick sort.pdfquick sort.pdf
quick sort.pdf
 
Unit 3 - Greedy Method
Unit 3  - Greedy MethodUnit 3  - Greedy Method
Unit 3 - Greedy Method
 
Unit 3 greedy method
Unit 3  greedy methodUnit 3  greedy method
Unit 3 greedy method
 
Graph Traversals
Graph TraversalsGraph Traversals
Graph Traversals
 

Recently uploaded

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
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
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
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
 
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...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

tree traversals.pdf

  • 1. Tree Traversals Ms. Mary Jacob Assistant Professor Kristu Jayanti College (Autonomous),Bangalore
  • 2. 1.Tree- Definition 2.Binary tree 3.Binary tree - Properties 4.Traversals CONTENTS
  • 3. A Tree is a data structure that emulates a hierarchical tree structure with a set of linked nodes. It is a data structure accessed beginning at the root node. Each node is either a leaf or an internal node. An internal node has one or more child nodes and is called the parent of its child nodes. All children of the same node are siblings. Contrary to a physical tree, the root is usually depicted at the top of the structure, and the leaves are depicted at the bottom. Ø A Tree is a data structure that emulates a hierarchical tree structure with a set of linked nodes. Ø It is a data structure accessed beginning at the root node. Each node is either a leaf or an internal node. Ø An internal node has one or more child nodes and is called the parent of its child nodes. All children of the same node are siblings. Tree- Definition
  • 4. A Tree is a data structure that emulates a hierarchical tree structure with a set of linked nodes. It is a data structure accessed beginning at the root node. Each node is either a leaf or an internal node. An internal node has one or more child nodes and is called the parent of its child nodes. All children of the same node are siblings. Contrary to a physical tree, the root is usually depicted at the top of the structure, and the leaves are depicted at the bottom. Ø Root: node without parent (A) Ø Internal node: node with at least one child (A, B, C, F) Ø External node: a kind of leaf node without children (E, I, J, K, G, H, D) Ø Ancestors of a node: parent, grandparent, grand-grandparent, etc Ø Depth of a node: number of ancestors Ø Height of a tree: maximum depth of any node (3) Ø Descendant of a node: child, grandchild, grand-grandchild, etc Ø Degree of an element: no. of children it has Ø Sub tree: tree consisting of a node and its descendants Ø Path: traversal from node to node along the edges that results in a sequence Ø Root: node at the top of the tree Ø Parent: any node, except root has exactly one edge running upward to another node. The node above it is called parent. Tree Terminologies
  • 5. A Tree is a data structure that emulates a hierarchical tree structure with a set of linked nodes. It is a data structure accessed beginning at the root node. Each node is either a leaf or an internal node. An internal node has one or more child nodes and is called the parent of its child nodes. All children of the same node are siblings. Contrary to a physical tree, the root is usually depicted at the top of the structure, and the leaves are depicted at the bottom. Ø Child: any node may have one or more lines running downward to other nodes. Nodes below are children. Ø Leaf: a node that has no children Ø Sub tree: any node can be considered to be the root of a subtree, which consists of its children and its children's children and so on. Ø Visiting: a node is visited when program control arrives at the node, usually for processing. Ø Traversing: to traverse a tree means to visit all the nodes in some specified order. Ø Levels: the level of a particular node refers to how many generations the node is from the root. Root is assumed to be level 0. Tree Terminologies
  • 6. A Tree is a data structure that emulates a hierarchical tree structure with a set of linked nodes. It is a data structure accessed beginning at the root node. Each node is either a leaf or an internal node. An internal node has one or more child nodes and is called the parent of its child nodes. All children of the same node are siblings. Contrary to a physical tree, the root is usually depicted at the top of the structure, and the leaves are depicted at the bottom. Ø Binary tree is a set of finite nodes which is either empty or consists of one or more nodes in which each node has at most two disjoint binary sub trees called left sub tree or right sub tree respectively. Ø There may be a zero degree node or a one degree node or a two degree node. Binary Tree
  • 7. A Tree is a data structure that emulates a hierarchical tree structure with a set of linked nodes. It is a data structure accessed beginning at the root node. Each node is either a leaf or an internal node. An internal node has one or more child nodes and is called the parent of its child nodes. All children of the same node are siblings. Contrary to a physical tree, the root is usually depicted at the top of the structure, and the leaves are depicted at the bottom. Binary Tree - Properties Ø The maximum number of nodes at a level I of binary tree is 2I where I>=0. Ø If h = height of a binary tree, max number of nodes possible in a binary tree of height h is 2h-1 min number of nodes possible in a binary tree of height h is h Ø For any non empty tree, number of terminal or leaf nodes is equal to number of non terminal nodes(internal nodes) +1. Ø For any non empty binary tree, if ‘n’ is the number of nodes and ‘e’ is the number of edges, then n=e+1; Ø Total number of binary trees possible with n nodes is 1/(n+1)2ncn Ø A binary tree with height h and 2h + 1 - 1 nodes (or 2h leaves) is called a full binary tree
  • 8. A Tree is a data structure that emulates a hierarchical tree structure with a set of linked nodes. It is a data structure accessed beginning at the root node. Each node is either a leaf or an internal node. An internal node has one or more child nodes and is called the parent of its child nodes. All children of the same node are siblings. Contrary to a physical tree, the root is usually depicted at the top of the structure, and the leaves are depicted at the bottom. Traversals of a Binary Tree The tree can be traversed in inorder, preorder and postorder methods. PREORDER TRAVERSAL: Ø Process the root R. Ø Traverse the left sub tree of R in preorder. Ø Traverse the right sub tree of R in preorder. INORDER TRAVERSAL: Ø Traverse the left sub tree of R in inorder. Ø Process the root R. Ø Traverse the right sub tree of R in inorder. POSTORDER TRAVERSAL : Ø Traverse the left sub tree of R in postorder. Ø Traverse the right sub tree of R in postorder. Ø Process the root R.
  • 9. The order in which each node in the tree is traversed is as follows, INORDER TRAVERSAL:10,15 ,16 ,32 ,33,34,87 PREORDER TRAVERSAL :32 ,16,10,15,34,33,87 POSTORDER TRAVERSAL :15, 10, 16, 33, 87, 34, 32 Traversals of a Binary Tree -Example The order in which each node in the tree is traversed is as follows, INORDER TRAVERSAL:10,15 ,16 ,32 ,33,34,87 PREORDER TRAVERSAL :32 ,16,10,15,34,33,87 POSTORDER TRAVERSAL :15, 10, 16, 33, 87, 34, 32