SlideShare a Scribd company logo
Trees
• So far we discussed mainly data structure - string, arrays, list
stacks, queues etc
• Now, we discuss about non-linear data structure called trees
• It is a data Structure that organizes data in a hierarchical model
with multiple levels
• Consider a parent-child relationship
.
Tree Data Structure & methods & operations
Tree Data Structure & methods & operations
Hierarchy Model
Sequence of Nodes like a family tree
structure
Starting from a Root node
Every node is parent of their belows
called childs
Nodes that are linked to both a parent
called siblings to each other
Main Terminology
Root
 Root
 Parent
 Siblings
 Child
 Descendents
 Ancestors
 Degree of Nodes
 Internal/External nodes
 Levels
 Height
Descendants
All nodes that can be reached from a node by following child
links.
Ancestors
All nodes along the path from a given node to the root.
Degree of Nodes
The number of children a node has
.
Internal/External Nodes
Internal nodes have children, while external nodes (leaves) do
not.
Levels
The distance from the root to a given node.
Height
The longest path from the root to a leaf node.
Types of Binary Trees
1. Full Binary Tree
A Binary Tree is a full binary tree if every node has 0 or 2
children. A full Binary tree is a special type of binary tree in
which every parent node/internal node has either two or no
children.
2. Perfect Binary Tree
 Internal have exactly 2 children
 All leaf nodes are on same level
3. Complete Binary Tree
A complete binary tree is just like a full binary tree, but with two
major differences:
Every level except the last level must be completely filled.
All the leaf elements must lean towards the left.
The last leaf element might not have a right sibling i.e. a
complete binary tree doesn’t have to be a full binary tree.
4. Skewed Binary Tree
A skewed binary tree is a pathological/degenerate tree and there
are two types of skewed binary tree: left-skewed binary tree and
right-skewed binary tree.
5. Binary Search Tree
Binary Search Tree is a node-based binary tree data structure that
has the following properties:
The left subtree of a node contains only nodes with keys lesser
than the node’s key.
The right subtree of a node contains only nodes with keys
greater than the node’s key.
The left and right subtree each must also be a binary search
tree.
Tree Traversals
Traversals means ‘VISITING’ their elements.
Preorder: visit(node), preorder(LNSubtree), preorder(RNSubtree)
Inorder: inorder(left), visit(node), inorder(right)
Postorder: postorder(left), postorder(right), visit(node)
Levelorder: Level by level
Tree Traversals Easy Method ‘I’
Preorder Inorder Postorder
A
C
G
B
F
E
D
C
B
A
G
F
E
D
C
B
G
F
E
A
D
A,B,D,E,C,F,G D,B,E,A,F,C,G D,E,B,F,G,C,A
Tree Traversals Easy Method ‘II’
PostOrder InOrder PreOrder
Level Order of Traversal
Tree traversal method that visits nodes level
by level, starting from the root and moving
downwards to each successive level, from
left to right. It’s often referred to as a
Breadth-First Search (BFS) for trees because
it explores each level entirely before moving
to the next.
C
B
F
E
A
G
D
A,B,C,D,E,F,G
Tree Operations
Insertion
Deletion
Searching
Root
1. Insertion:
Inserting a new element (node) into the tree, typically by
following a certain rule to place it in the correct position.
Example:
Imagine a family tree. When a new child is born, they are added
as a child under their parents. The tree grows, but the family
structure remains intact with the new addition.
Insertion
2. Searching
Finding a specific node within the tree based on a given value.
Example:
In an organizational chart, if you’re trying to locate an employee,
you might start at the top (CEO) and search down through
departments until you find them.
Tree Data Structure & methods & operations
3. Deletion
When removing from a binary search tree, we are concerned
with keeping the rest of the tree in the correct order.
This means removing is different depending on whether the
node we are removing has children.
There are three cases for deleting a node:
1.Leaf Node
2.Single Child
3.Having two children
Leaf Node
One Child
Two Child
Two Child
Thank you
.

More Related Content

PPTX
trees in data structure
PPTX
Why Tree is considered a non-linear data structure?
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPTX
Tree structure and its definitions with an example
PPTX
NON-LINEAR DATA STRUCTURE-TREES.pptx
PPTX
Tree
PPSX
data structure(tree operations)
PPTX
binary tree.pptx
trees in data structure
Why Tree is considered a non-linear data structure?
UNIT III Non Linear Data Structures - Trees.pptx
Tree structure and its definitions with an example
NON-LINEAR DATA STRUCTURE-TREES.pptx
Tree
data structure(tree operations)
binary tree.pptx

Similar to Tree Data Structure & methods & operations (20)

PPTX
Introduction to Tree_Data Structure.pptx
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPT
PPTX
tree Data Structures in python Traversals.pptx
PPTX
Team-hawks_DSA_binary_tree[1] [Read-Only].pptx
PPTX
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
PPTX
Data Structures using Python(generic elective).pptx
PPTX
Unit 6 tree
PPTX
tree-160731205832.pptx
PPTX
Binary tree
PPTX
learn tree, linked list, queue, stack, and other algo
PPT
Data Structure And Algorithms for Computer Science
PPT
9. TREE Data Structure Non Linear Data Structure
PPTX
BST.pptx this is Good for data structure
PPTX
BST.pptx this isp used for learning binary search trees
PPTX
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
PPTX
Data Structures and Algorithms - Lecture 10 - Thushapan.pptx
PPT
Tree and Binary Search tree
PPTX
Binary Trees.pptx module 122img 787554yau
PPTX
07-Lecture.pptxlkjslkjdfkjskljdflksj;fdkj
Introduction to Tree_Data Structure.pptx
UNIT III Non Linear Data Structures - Trees.pptx
tree Data Structures in python Traversals.pptx
Team-hawks_DSA_binary_tree[1] [Read-Only].pptx
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
Data Structures using Python(generic elective).pptx
Unit 6 tree
tree-160731205832.pptx
Binary tree
learn tree, linked list, queue, stack, and other algo
Data Structure And Algorithms for Computer Science
9. TREE Data Structure Non Linear Data Structure
BST.pptx this is Good for data structure
BST.pptx this isp used for learning binary search trees
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
Data Structures and Algorithms - Lecture 10 - Thushapan.pptx
Tree and Binary Search tree
Binary Trees.pptx module 122img 787554yau
07-Lecture.pptxlkjslkjdfkjskljdflksj;fdkj
Ad

Recently uploaded (20)

PDF
Nekopoi APK 2025 free lastest update
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
AI in Product Development-omnex systems
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
System and Network Administraation Chapter 3
Nekopoi APK 2025 free lastest update
CHAPTER 2 - PM Management and IT Context
Navsoft: AI-Powered Business Solutions & Custom Software Development
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How to Migrate SBCGlobal Email to Yahoo Easily
wealthsignaloriginal-com-DS-text-... (1).pdf
Reimagine Home Health with the Power of Agentic AI​
2025 Textile ERP Trends: SAP, Odoo & Oracle
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Design an Analysis of Algorithms II-SECS-1021-03
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Odoo Companies in India – Driving Business Transformation.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
AI in Product Development-omnex systems
Upgrade and Innovation Strategies for SAP ERP Customers
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
System and Network Administraation Chapter 3
Ad

Tree Data Structure & methods & operations

  • 1. Trees • So far we discussed mainly data structure - string, arrays, list stacks, queues etc • Now, we discuss about non-linear data structure called trees • It is a data Structure that organizes data in a hierarchical model with multiple levels • Consider a parent-child relationship
  • 2. .
  • 5. Hierarchy Model Sequence of Nodes like a family tree structure Starting from a Root node Every node is parent of their belows called childs Nodes that are linked to both a parent called siblings to each other
  • 6. Main Terminology Root  Root  Parent  Siblings  Child  Descendents  Ancestors  Degree of Nodes  Internal/External nodes  Levels  Height
  • 7. Descendants All nodes that can be reached from a node by following child links. Ancestors All nodes along the path from a given node to the root. Degree of Nodes The number of children a node has
  • 8. . Internal/External Nodes Internal nodes have children, while external nodes (leaves) do not. Levels The distance from the root to a given node. Height The longest path from the root to a leaf node.
  • 9. Types of Binary Trees 1. Full Binary Tree A Binary Tree is a full binary tree if every node has 0 or 2 children. A full Binary tree is a special type of binary tree in which every parent node/internal node has either two or no children.
  • 10. 2. Perfect Binary Tree  Internal have exactly 2 children  All leaf nodes are on same level
  • 11. 3. Complete Binary Tree A complete binary tree is just like a full binary tree, but with two major differences: Every level except the last level must be completely filled. All the leaf elements must lean towards the left. The last leaf element might not have a right sibling i.e. a complete binary tree doesn’t have to be a full binary tree.
  • 12. 4. Skewed Binary Tree A skewed binary tree is a pathological/degenerate tree and there are two types of skewed binary tree: left-skewed binary tree and right-skewed binary tree.
  • 13. 5. Binary Search Tree Binary Search Tree is a node-based binary tree data structure that has the following properties: The left subtree of a node contains only nodes with keys lesser than the node’s key. The right subtree of a node contains only nodes with keys greater than the node’s key. The left and right subtree each must also be a binary search tree.
  • 14. Tree Traversals Traversals means ‘VISITING’ their elements. Preorder: visit(node), preorder(LNSubtree), preorder(RNSubtree) Inorder: inorder(left), visit(node), inorder(right) Postorder: postorder(left), postorder(right), visit(node) Levelorder: Level by level
  • 15. Tree Traversals Easy Method ‘I’ Preorder Inorder Postorder A C G B F E D C B A G F E D C B G F E A D A,B,D,E,C,F,G D,B,E,A,F,C,G D,E,B,F,G,C,A
  • 16. Tree Traversals Easy Method ‘II’ PostOrder InOrder PreOrder
  • 17. Level Order of Traversal Tree traversal method that visits nodes level by level, starting from the root and moving downwards to each successive level, from left to right. It’s often referred to as a Breadth-First Search (BFS) for trees because it explores each level entirely before moving to the next. C B F E A G D A,B,C,D,E,F,G
  • 19. 1. Insertion: Inserting a new element (node) into the tree, typically by following a certain rule to place it in the correct position. Example: Imagine a family tree. When a new child is born, they are added as a child under their parents. The tree grows, but the family structure remains intact with the new addition.
  • 21. 2. Searching Finding a specific node within the tree based on a given value. Example: In an organizational chart, if you’re trying to locate an employee, you might start at the top (CEO) and search down through departments until you find them.
  • 23. 3. Deletion When removing from a binary search tree, we are concerned with keeping the rest of the tree in the correct order. This means removing is different depending on whether the node we are removing has children. There are three cases for deleting a node: 1.Leaf Node 2.Single Child 3.Having two children