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
.
Ad

More Related Content

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

UNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptxUNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptx
VISWANATHAN R V
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
JITTAYASHWANTHREDDY
 
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
RupaRaj6
 
Team-hawks_DSA_binary_tree[1] [Read-Only].pptx
Team-hawks_DSA_binary_tree[1] [Read-Only].pptxTeam-hawks_DSA_binary_tree[1] [Read-Only].pptx
Team-hawks_DSA_binary_tree[1] [Read-Only].pptx
XEON14
 
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptxDS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DRCARIBOU
 
Data Structures using Python(generic elective).pptx
Data Structures using Python(generic elective).pptxData Structures using Python(generic elective).pptx
Data Structures using Python(generic elective).pptx
mastimajakDKS
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
Dabbal Singh Mahara
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
MouDhara1
 
Binary tree
Binary treeBinary tree
Binary tree
MKalpanaDevi
 
learn tree, linked list, queue, stack, and other algo
learn tree, linked list, queue, stack, and other algolearn tree, linked list, queue, stack, and other algo
learn tree, linked list, queue, stack, and other algo
unknowwqer
 
Data Structure And Algorithms for Computer Science
Data Structure And Algorithms for Computer ScienceData Structure And Algorithms for Computer Science
Data Structure And Algorithms for Computer Science
ManishShukla712917
 
9. TREE Data Structure Non Linear Data Structure
9. TREE Data Structure Non Linear Data Structure9. TREE Data Structure Non Linear Data Structure
9. TREE Data Structure Non Linear Data Structure
kejika1215
 
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
BASIC TREE  AND TYPES OF DI CONCEPTS.pptxBASIC TREE  AND TYPES OF DI CONCEPTS.pptx
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
tpvvsreenivasarao
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
Muhazzab Chouhadry
 
Binary Trees.pptx module 122img 787554yau
Binary Trees.pptx module 122img 787554yauBinary Trees.pptx module 122img 787554yau
Binary Trees.pptx module 122img 787554yau
rithusagar5
 
Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
MD. MARUFUZZAMAN .
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
LavanyaJ28
 
Binary trees
Binary treesBinary trees
Binary trees
Abhishek Khune
 
Trees
TreesTrees
Trees
Shankar Bishnoi
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
UNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptxUNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptx
VISWANATHAN R V
 
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
RupaRaj6
 
Team-hawks_DSA_binary_tree[1] [Read-Only].pptx
Team-hawks_DSA_binary_tree[1] [Read-Only].pptxTeam-hawks_DSA_binary_tree[1] [Read-Only].pptx
Team-hawks_DSA_binary_tree[1] [Read-Only].pptx
XEON14
 
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptxDS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
DRCARIBOU
 
Data Structures using Python(generic elective).pptx
Data Structures using Python(generic elective).pptxData Structures using Python(generic elective).pptx
Data Structures using Python(generic elective).pptx
mastimajakDKS
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
MouDhara1
 
learn tree, linked list, queue, stack, and other algo
learn tree, linked list, queue, stack, and other algolearn tree, linked list, queue, stack, and other algo
learn tree, linked list, queue, stack, and other algo
unknowwqer
 
Data Structure And Algorithms for Computer Science
Data Structure And Algorithms for Computer ScienceData Structure And Algorithms for Computer Science
Data Structure And Algorithms for Computer Science
ManishShukla712917
 
9. TREE Data Structure Non Linear Data Structure
9. TREE Data Structure Non Linear Data Structure9. TREE Data Structure Non Linear Data Structure
9. TREE Data Structure Non Linear Data Structure
kejika1215
 
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
BASIC TREE  AND TYPES OF DI CONCEPTS.pptxBASIC TREE  AND TYPES OF DI CONCEPTS.pptx
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
tpvvsreenivasarao
 
Binary Trees.pptx module 122img 787554yau
Binary Trees.pptx module 122img 787554yauBinary Trees.pptx module 122img 787554yau
Binary Trees.pptx module 122img 787554yau
rithusagar5
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 

Recently uploaded (20)

Call of Duty: Warzone for Windows With Crack Free Download 2025
Call of Duty: Warzone for Windows With Crack Free Download 2025Call of Duty: Warzone for Windows With Crack Free Download 2025
Call of Duty: Warzone for Windows With Crack Free Download 2025
Iobit Uninstaller Pro Crack
 
Lumion Pro Crack + 2025 Activation Key Free Code
Lumion Pro Crack + 2025 Activation Key Free CodeLumion Pro Crack + 2025 Activation Key Free Code
Lumion Pro Crack + 2025 Activation Key Free Code
raheemk1122g
 
Hyper Casual Game Developers Company
Hyper  Casual  Game  Developers  CompanyHyper  Casual  Game  Developers  Company
Hyper Casual Game Developers Company
Nova Carter
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Welcome to QA Summit 2025.
Welcome to QA Summit 2025.Welcome to QA Summit 2025.
Welcome to QA Summit 2025.
QA Summit
 
Catching Wire; An introduction to CBWire 4
Catching Wire; An introduction to CBWire 4Catching Wire; An introduction to CBWire 4
Catching Wire; An introduction to CBWire 4
Ortus Solutions, Corp
 
Temas principales de GrafanaCON 2025 Grafana 12 y más
Temas principales de GrafanaCON 2025 Grafana 12 y másTemas principales de GrafanaCON 2025 Grafana 12 y más
Temas principales de GrafanaCON 2025 Grafana 12 y más
Imma Valls Bernaus
 
Choose Your Own Adventure to Get Started with Grafana Loki
Choose Your Own Adventure to Get Started with Grafana LokiChoose Your Own Adventure to Get Started with Grafana Loki
Choose Your Own Adventure to Get Started with Grafana Loki
Imma Valls Bernaus
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
Quasar Framework Introduction for C++ develpoers
Quasar Framework Introduction for C++ develpoersQuasar Framework Introduction for C++ develpoers
Quasar Framework Introduction for C++ develpoers
sadadkhah
 
Let's Do Bad Things to Unsecured Containers
Let's Do Bad Things to Unsecured ContainersLet's Do Bad Things to Unsecured Containers
Let's Do Bad Things to Unsecured Containers
Gene Gotimer
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Multi-Agent Era will Define the Future of Software
Multi-Agent Era will Define the Future of SoftwareMulti-Agent Era will Define the Future of Software
Multi-Agent Era will Define the Future of Software
Ivo Andreev
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Drawing Heighway’s Dragon - Part 4 - Interactive and Animated Dragon Creation
Drawing Heighway’s Dragon - Part 4 - Interactive and Animated Dragon CreationDrawing Heighway’s Dragon - Part 4 - Interactive and Animated Dragon Creation
Drawing Heighway’s Dragon - Part 4 - Interactive and Animated Dragon Creation
Philip Schwarz
 
SamFw Tool v4.9 Samsung Frp Tool Free Download
SamFw Tool v4.9 Samsung Frp Tool Free DownloadSamFw Tool v4.9 Samsung Frp Tool Free Download
SamFw Tool v4.9 Samsung Frp Tool Free Download
Iobit Uninstaller Pro Crack
 
Why CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Why CoTester Is the AI Testing Tool QA Teams Can’t IgnoreWhy CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Why CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Shubham Joshi
 
Legacy Code Nightmares , Hellscapes, and Lessons Learned.pdf
Legacy Code Nightmares , Hellscapes, and Lessons Learned.pdfLegacy Code Nightmares , Hellscapes, and Lessons Learned.pdf
Legacy Code Nightmares , Hellscapes, and Lessons Learned.pdf
Ortus Solutions, Corp
 
Call of Duty: Warzone for Windows With Crack Free Download 2025
Call of Duty: Warzone for Windows With Crack Free Download 2025Call of Duty: Warzone for Windows With Crack Free Download 2025
Call of Duty: Warzone for Windows With Crack Free Download 2025
Iobit Uninstaller Pro Crack
 
Lumion Pro Crack + 2025 Activation Key Free Code
Lumion Pro Crack + 2025 Activation Key Free CodeLumion Pro Crack + 2025 Activation Key Free Code
Lumion Pro Crack + 2025 Activation Key Free Code
raheemk1122g
 
Hyper Casual Game Developers Company
Hyper  Casual  Game  Developers  CompanyHyper  Casual  Game  Developers  Company
Hyper Casual Game Developers Company
Nova Carter
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Welcome to QA Summit 2025.
Welcome to QA Summit 2025.Welcome to QA Summit 2025.
Welcome to QA Summit 2025.
QA Summit
 
Catching Wire; An introduction to CBWire 4
Catching Wire; An introduction to CBWire 4Catching Wire; An introduction to CBWire 4
Catching Wire; An introduction to CBWire 4
Ortus Solutions, Corp
 
Temas principales de GrafanaCON 2025 Grafana 12 y más
Temas principales de GrafanaCON 2025 Grafana 12 y másTemas principales de GrafanaCON 2025 Grafana 12 y más
Temas principales de GrafanaCON 2025 Grafana 12 y más
Imma Valls Bernaus
 
Choose Your Own Adventure to Get Started with Grafana Loki
Choose Your Own Adventure to Get Started with Grafana LokiChoose Your Own Adventure to Get Started with Grafana Loki
Choose Your Own Adventure to Get Started with Grafana Loki
Imma Valls Bernaus
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
Quasar Framework Introduction for C++ develpoers
Quasar Framework Introduction for C++ develpoersQuasar Framework Introduction for C++ develpoers
Quasar Framework Introduction for C++ develpoers
sadadkhah
 
Let's Do Bad Things to Unsecured Containers
Let's Do Bad Things to Unsecured ContainersLet's Do Bad Things to Unsecured Containers
Let's Do Bad Things to Unsecured Containers
Gene Gotimer
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Multi-Agent Era will Define the Future of Software
Multi-Agent Era will Define the Future of SoftwareMulti-Agent Era will Define the Future of Software
Multi-Agent Era will Define the Future of Software
Ivo Andreev
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Drawing Heighway’s Dragon - Part 4 - Interactive and Animated Dragon Creation
Drawing Heighway’s Dragon - Part 4 - Interactive and Animated Dragon CreationDrawing Heighway’s Dragon - Part 4 - Interactive and Animated Dragon Creation
Drawing Heighway’s Dragon - Part 4 - Interactive and Animated Dragon Creation
Philip Schwarz
 
Why CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Why CoTester Is the AI Testing Tool QA Teams Can’t IgnoreWhy CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Why CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Shubham Joshi
 
Legacy Code Nightmares , Hellscapes, and Lessons Learned.pdf
Legacy Code Nightmares , Hellscapes, and Lessons Learned.pdfLegacy Code Nightmares , Hellscapes, and Lessons Learned.pdf
Legacy Code Nightmares , Hellscapes, and Lessons Learned.pdf
Ortus Solutions, Corp
 
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
  翻译: