SlideShare a Scribd company logo
2
Most read
6
Most read
24
Most read
Trees
Introduction
 Is a non linear data structure.
 Is a hierarchical data structure.
 Is a finite set of nodes.
 Contains a special node called root node.
 All nodes are connecting through an edge.
Trees
Terminologies…
 Degree of a Node
Means number of child nodes a node have.
 Leaf
Nodes that have no child nodes.
 Terminal Nodes
Leaf nodes are also called terminal nodes.
 Degree of a tree
Maximum degree of tree is called degree of
tree.
 Ancestors
All the parent nodes of a node till rood node
path called its ancestors.
 Descendants
All the child nodes of a node till leaf node
path called its ancestors.
 Generation
All nodes with same level called a generation.
 Height/Depth
Number of levels / Generations .
 Edge
Connecting lines that are used to connect
nodes.
 Path
sequence of consective edges from 1 node
to other node.
 Branch
if a path ends at leaf nodes called branch.
How to construct tree data
structure.
 We can construct it using Linked List.
Binary Tree
 A tree having a property that all nodes should
have minimum 0 nodes or maximum 2 nodes.
>=0 nodes <=2.
 If 0 nodes called empty tree/null tree.
Trees
Types
1: Full BT
- a tree in which each level is filled
completely.
- non leaf nodes should have left as well as
right child's.
- all the leaf nodes should be at same level.
Trees
2: Complete Binary tree
each node must have 2 child's (left and right
as well) except leaf nodes.
3: Incomplete binary tree
tree may violate the property of complete
binary tree.
Trees
Almost complete binary tree
 A tree having all leaf nodes at last or second
last level called almost complete binary tree.
Binary Search Tree
 A binary tree in which minimum value is
placed at the left side of node and maximum
value at right side of node.
Operations
 Insertion
 Searching
 Deletion
Insertion in BST
 Place first at root node.
 Now compare each node value to decide
whether your coming value will be placed at
right or left side of node.
 Takes O(n) in worst case
 Takes Big-Theta (log n) in average case.
Searching
 Compare the target value by moving from one
node to other starting from root node.
 Move left if targeted value is smaller than
node value else move right.
 Takes O(n) in worst case
 Takes Big-Theta (log n) in average case.
Deletion
 Cases
 If the node is leaf
 If node in non-leaf and have 1 child node.
 If node is non-leaf and have 2 child nodes.
If the node is leaf
 Delete that node and make its father node
pointing to Null.
 Left pointer in case of left leaf
 Right pointer in case of right leaf
If node is non-leaf and having 1
child node.
 If deleted node is right child of its parent
 Delete the node.
 If have right child or Left Child
 Make it the Right child of deleted node’s
parent.
 If deleted node is left child of its parent
 Delete the node.
 If have right child or Left Child
 Make it the left child of deleted node’s
parent.
Trees

More Related Content

PPT
Binary tree
PDF
Binary tree
PPT
1.5 binary search tree
PPT
Unit 3 Tree chapter 5
PPT
Data Structure and Algorithms Binary Search Tree
PPTX
NON-LINEAR DATA STRUCTURE-TREES.pptx
PPSX
Data Structure (Tree)
PPT
Binary tree
Binary tree
Binary tree
1.5 binary search tree
Unit 3 Tree chapter 5
Data Structure and Algorithms Binary Search Tree
NON-LINEAR DATA STRUCTURE-TREES.pptx
Data Structure (Tree)
Binary tree

What's hot (20)

PPTX
Doubly Linked List
PPTX
Binary Tree in Data Structure
PPSX
Data Structure (Queue)
PPTX
Hashing in datastructure
PPTX
Priority Queue in Data Structure
PPTX
Linear Search
PPTX
Tree in data structure
PPTX
Binary Search Tree
PPTX
B and B+ tree
PPT
Binary search tree in data structures
PPT
1.1 binary tree
PPTX
Circular link list.ppt
PPTX
Priority queue in DSA
PPT
Binary search tree(bst)
PPTX
Bfs and Dfs
PPTX
PPTX
Data structure & its types
PPTX
Linked list
PPTX
sorting and its types
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
Doubly Linked List
Binary Tree in Data Structure
Data Structure (Queue)
Hashing in datastructure
Priority Queue in Data Structure
Linear Search
Tree in data structure
Binary Search Tree
B and B+ tree
Binary search tree in data structures
1.1 binary tree
Circular link list.ppt
Priority queue in DSA
Binary search tree(bst)
Bfs and Dfs
Data structure & its types
Linked list
sorting and its types
Trees, Binary Search Tree, AVL Tree in Data Structures
Ad

Similar to Trees (20)

PPT
PPTX
Tree Data Structure & methods & operations
PPTX
trees in data structure
PPTX
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
PPT
Lecture 5 tree.pptx
PPTX
Introduction to Tree_Data Structure.pptx
PDF
Chapter 7 - Binary Search Tree in the context of DSA.pdf
PPTX
Unit 3 trees
PPTX
Binary tree
PPSX
data structure(tree operations)
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPTX
BST.pptx this is Good for data structure
PPTX
BST.pptx this isp used for learning binary search trees
PPTX
Why Tree is considered a non-linear data structure?
PPT
tree.ppt
PPT
BINARY SEARCH TREE
PPTX
Binary Search Tree.pptx
PPTX
datastructurestreeand type of trees.pptx
PPTX
Data structures 3
Tree Data Structure & methods & operations
trees in data structure
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
Lecture 5 tree.pptx
Introduction to Tree_Data Structure.pptx
Chapter 7 - Binary Search Tree in the context of DSA.pdf
Unit 3 trees
Binary tree
data structure(tree operations)
UNIT III Non Linear Data Structures - Trees.pptx
BST.pptx this is Good for data structure
BST.pptx this isp used for learning binary search trees
Why Tree is considered a non-linear data structure?
tree.ppt
BINARY SEARCH TREE
Binary Search Tree.pptx
datastructurestreeand type of trees.pptx
Data structures 3
Ad

More from Burhan Ahmed (20)

PPTX
Wireless mobile communication
PPTX
Virtual function
PPTX
Uses misuses and risk of software
PPTX
Types of computer
PPTX
Topology
PPTX
The distinction of prophet muhammad (s.a.w) among the teachers of moral conduct
PPTX
Software house organization
PPT
Social interaction
PPTX
Role model
PPTX
Rights and duties
PPTX
Planning work activities
PPTX
Peripheral devices
PPTX
Parallel computing and its applications
PPTX
Operator overloading
PPT
Normalization
PPTX
Managing strategy
PPT
Letter writing
PPTX
Job analysis and job design
PPTX
Intellectual property
PPTX
Inheritance
Wireless mobile communication
Virtual function
Uses misuses and risk of software
Types of computer
Topology
The distinction of prophet muhammad (s.a.w) among the teachers of moral conduct
Software house organization
Social interaction
Role model
Rights and duties
Planning work activities
Peripheral devices
Parallel computing and its applications
Operator overloading
Normalization
Managing strategy
Letter writing
Job analysis and job design
Intellectual property
Inheritance

Recently uploaded (20)

PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Classroom Observation Tools for Teachers
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cell Types and Its function , kingdom of life
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Institutional Correction lecture only . . .
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Classroom Observation Tools for Teachers
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
RMMM.pdf make it easy to upload and study
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
Cell Types and Its function , kingdom of life
STATICS OF THE RIGID BODIES Hibbelers.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Institutional Correction lecture only . . .
FourierSeries-QuestionsWithAnswers(Part-A).pdf
TR - Agricultural Crops Production NC III.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

Trees

  • 2. Introduction  Is a non linear data structure.  Is a hierarchical data structure.  Is a finite set of nodes.  Contains a special node called root node.  All nodes are connecting through an edge.
  • 4. Terminologies…  Degree of a Node Means number of child nodes a node have.  Leaf Nodes that have no child nodes.  Terminal Nodes Leaf nodes are also called terminal nodes.
  • 5.  Degree of a tree Maximum degree of tree is called degree of tree.  Ancestors All the parent nodes of a node till rood node path called its ancestors.  Descendants All the child nodes of a node till leaf node path called its ancestors.
  • 6.  Generation All nodes with same level called a generation.  Height/Depth Number of levels / Generations .  Edge Connecting lines that are used to connect nodes.
  • 7.  Path sequence of consective edges from 1 node to other node.  Branch if a path ends at leaf nodes called branch.
  • 8. How to construct tree data structure.  We can construct it using Linked List.
  • 9. Binary Tree  A tree having a property that all nodes should have minimum 0 nodes or maximum 2 nodes. >=0 nodes <=2.  If 0 nodes called empty tree/null tree.
  • 11. Types 1: Full BT - a tree in which each level is filled completely. - non leaf nodes should have left as well as right child's. - all the leaf nodes should be at same level.
  • 13. 2: Complete Binary tree each node must have 2 child's (left and right as well) except leaf nodes. 3: Incomplete binary tree tree may violate the property of complete binary tree.
  • 15. Almost complete binary tree  A tree having all leaf nodes at last or second last level called almost complete binary tree.
  • 16. Binary Search Tree  A binary tree in which minimum value is placed at the left side of node and maximum value at right side of node.
  • 18. Insertion in BST  Place first at root node.  Now compare each node value to decide whether your coming value will be placed at right or left side of node.  Takes O(n) in worst case  Takes Big-Theta (log n) in average case.
  • 19. Searching  Compare the target value by moving from one node to other starting from root node.  Move left if targeted value is smaller than node value else move right.  Takes O(n) in worst case  Takes Big-Theta (log n) in average case.
  • 20. Deletion  Cases  If the node is leaf  If node in non-leaf and have 1 child node.  If node is non-leaf and have 2 child nodes.
  • 21. If the node is leaf  Delete that node and make its father node pointing to Null.  Left pointer in case of left leaf  Right pointer in case of right leaf
  • 22. If node is non-leaf and having 1 child node.  If deleted node is right child of its parent  Delete the node.  If have right child or Left Child  Make it the Right child of deleted node’s parent.
  • 23.  If deleted node is left child of its parent  Delete the node.  If have right child or Left Child  Make it the left child of deleted node’s parent.