SlideShare a Scribd company logo
Created by  Zaheer Abbas Aghani   2K9 152
Non-Linear Data Structure TREE Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
Definition: Tree is a type of non-linear data structure that is mainly used to represent data containing a hierarchical relationship between elements. e.g. records, family tree and table of contents. In tree every node has three fields, first represent the data while second & third keep the information of left & right child of node. Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
There are several ways to represent tree structure. We will use graph to represent tree in which every node will be represented by circle and a line from one node to other is called edge. Node Edge Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC) A B D E C F
A tree can be consists of following Parts: Node Root Node Parent Node Child Node Leaf Node Sub-tree Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
A node may contain a value or a condition or represent a separate data structure or a tree of its own. Each node in a tree has zero or more  child nodes , which are below it in the tree. nodes Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
The topmost node in a tree is called the  root node .  Being the topmost node, the root node will not have parents. It is the node at which operations on the tree commonly begin. root node Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
A node that has a child is called the  parent node  (or  ancestor  node , or  superior  ). Each node in tree has at most one parent except root node. parent node Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
A node that has a parent node is called the  child node.  Each node in tree has is child node except leaf node. parent node Child node Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
A node with no children is called a leaf node.  Most leaf nodes are at the bottom most level of tree. Since they are at the bottom most level, they do not have any children.  They are also referred to as terminal node. Leaf node Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
A  subtree  is a portion of a tree data structure that can be viewed as a complete tree in itself.  Any node in a tree , together with all the nodes below it, comprise a subtree of . The subtree corresponding to the root node is the entire tree;  the subtree corresponding to any other node is called is a  proper subtree Sub-tree Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
An  internal node  or  inner node  is any node of a tree that has child nodes and is thus not a leaf node.  An intermediate  node between the root and the leaf nodes is called an internal node. Internal nodes Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
First we study a special kind of tree called Binary tree, which can easily maintained in the computer. Binary tree can be define as a finite set of elements, called nodes. A binary tree can be either  empty or Each node has at most two children. Example:- Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC) A B D E C F
Each node in binary tree is assigned a level number. The level of each node in binary tree is defined as: Root of tree is defined as level 0 Level number of other nodes is 1 more than level number of its father node or parent node. Example: A C B LEVEL  0 LEVEL  1 Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
The depth or height of tree is one more than the largest level number of tree. For example if the largest level number of tree is 2 than its depth is calculate by 2+1=3. Example: LEVEL  0 LEVEL  1 A B C In this example  the largest level number is 1 therefore depth is 1+1=2 Depth=2 Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
Strictly Binary Tree:  If every internal node (non terminal node) has its non empty left & right children then it is called strictly binary tree. Here every internal node A, B, E has two non empty left and right child hence it is strictly binary tree. A B C D E F G Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
Complete Binary Tree:  A complete binary tree is a binary tree where all internal nodes have both children except the last node. In this tree the last node () has only one child. 3 1 2 4 5 6 Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
Extended Binary Tree:  A binary tree is called extended binary tree if every node of tree has zero or two children. It is also said to be 2-tree. In binary tree, most of the nodes have one child then we can add one more child and can extend it. So it can be converted to extended binary tree. Extended binary tree Binary Tree Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
Binary Search Tree:  A binary search tree is a binary tree in which each node has value greater than every node of left sub-tree and less than every node of right sub-tree. Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC) 50 45 22 48 75 85

More Related Content

PPT
Lect 19 Zaheer Abbas
PPTX
Trees in data structures
PPTX
PPTX
Data structure using c module 2
PPT
Tree data structure
PPTX
Tree in data structure
PPT
Chapter 8 ds
DOCX
Trees and Graphs in data structures and Algorithms
Lect 19 Zaheer Abbas
Trees in data structures
Data structure using c module 2
Tree data structure
Tree in data structure
Chapter 8 ds
Trees and Graphs in data structures and Algorithms

What's hot (20)

PPTX
Types of Tree in Data Structure in C++
PPTX
Data structure tree - intermediate
PPTX
PPTX
non linear data structure -introduction of tree
PPT
Tree-In Data Structure
PPT
Binary tree in data structures
PPT
Data Structures 4
PDF
Dsc++ unit 3 notes
PPT
Trees - Non Linear Data Structure
PPTX
Data structure tree - beginner
PPTX
B tree (computer Science)
PPT
introduction to_trees
PPTX
Unit 6 tree
PPTX
Unit – vi tree
PDF
Lecture notes data structures tree
PPT
358 33 powerpoint-slides_10-trees_chapter-10
PPTX
Introduction to tree ds
PPTX
Farhana shaikh webinar_treesindiscretestructure
PDF
07 trees
Types of Tree in Data Structure in C++
Data structure tree - intermediate
non linear data structure -introduction of tree
Tree-In Data Structure
Binary tree in data structures
Data Structures 4
Dsc++ unit 3 notes
Trees - Non Linear Data Structure
Data structure tree - beginner
B tree (computer Science)
introduction to_trees
Unit 6 tree
Unit – vi tree
Lecture notes data structures tree
358 33 powerpoint-slides_10-trees_chapter-10
Introduction to tree ds
Farhana shaikh webinar_treesindiscretestructure
07 trees
Ad

Viewers also liked (11)

PPT
Lect 15-16 Zaheer Abbas
PPT
Lect 11-12 Zaheer Abbas
PPT
Lect 9(pointers) Zaheer Abbas
DOC
Flip & flop by Zaheer Abbas Aghani
DOC
C# by Zaheer Abbas Aghani
PPT
Lect 22 Zaheer Abbas
PDF
It3 4 by Zaheer Abbas Aghani
PPT
Lect 14 Zaheer Abbas
PPT
Lect 3-4 Zaheer Abbas
PPT
Lect 10 Zaheer Abbas
PDF
C sharp chap6
Lect 15-16 Zaheer Abbas
Lect 11-12 Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
Flip & flop by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
Lect 22 Zaheer Abbas
It3 4 by Zaheer Abbas Aghani
Lect 14 Zaheer Abbas
Lect 3-4 Zaheer Abbas
Lect 10 Zaheer Abbas
C sharp chap6
Ad

Similar to Lect 21 Zaheer Abbas (20)

PPTX
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
PPTX
Data Structure of computer science and technology
PPTX
TREE PRESENTATION COMPUTER SCIENCE/DATA STRUCTURE
PPTX
Data Structures -Non Linear DS-Basics ofTrees
PPTX
TREES basics simple introduction .pptx
PPTX
TREES 1.pptx
PPT
Final tree.ppt tells about tree presentation
PPTX
Basic Tree Data Structure BST Traversals .pptx
DOCX
data structures Unit 3 notes.docxdata structures Unit 3 notes.docx
PPTX
trees assignment by Syed Muhammad Huzaifa.pptx
PPT
UNIT-4 TREES.ppt
PPTX
Trees, Basic Terminology and Binary Trees
PPTX
Binary Trees - Tree Terminologies and representation
PDF
tree traversals.pdf
PPTX
Tree all information about tree concept are available .
PPTX
Tree.pptx
PPTX
Data structure tree- advance
PDF
tree basics to advanced all concepts part 1
PPTX
notesCHAPTER_5_tree_data_structure_ds.pppt
PPTX
Tree Data Structure Tree Data Structure Details
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
Data Structure of computer science and technology
TREE PRESENTATION COMPUTER SCIENCE/DATA STRUCTURE
Data Structures -Non Linear DS-Basics ofTrees
TREES basics simple introduction .pptx
TREES 1.pptx
Final tree.ppt tells about tree presentation
Basic Tree Data Structure BST Traversals .pptx
data structures Unit 3 notes.docxdata structures Unit 3 notes.docx
trees assignment by Syed Muhammad Huzaifa.pptx
UNIT-4 TREES.ppt
Trees, Basic Terminology and Binary Trees
Binary Trees - Tree Terminologies and representation
tree traversals.pdf
Tree all information about tree concept are available .
Tree.pptx
Data structure tree- advance
tree basics to advanced all concepts part 1
notesCHAPTER_5_tree_data_structure_ds.pppt
Tree Data Structure Tree Data Structure Details

Recently uploaded (20)

PDF
project resource management chapter-09.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Encapsulation theory and applications.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
August Patch Tuesday
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Hindi spoken digit analysis for native and non-native speakers
project resource management chapter-09.pdf
Programs and apps: productivity, graphics, security and other tools
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Hybrid model detection and classification of lung cancer
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Chapter 5: Probability Theory and Statistics
Encapsulation theory and applications.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
cloud_computing_Infrastucture_as_cloud_p
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
August Patch Tuesday
A comparative analysis of optical character recognition models for extracting...
Heart disease approach using modified random forest and particle swarm optimi...
MIND Revenue Release Quarter 2 2025 Press Release
Hindi spoken digit analysis for native and non-native speakers

Lect 21 Zaheer Abbas

  • 1. Created by Zaheer Abbas Aghani 2K9 152
  • 2. Non-Linear Data Structure TREE Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 3. Definition: Tree is a type of non-linear data structure that is mainly used to represent data containing a hierarchical relationship between elements. e.g. records, family tree and table of contents. In tree every node has three fields, first represent the data while second & third keep the information of left & right child of node. Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 4. There are several ways to represent tree structure. We will use graph to represent tree in which every node will be represented by circle and a line from one node to other is called edge. Node Edge Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC) A B D E C F
  • 5. A tree can be consists of following Parts: Node Root Node Parent Node Child Node Leaf Node Sub-tree Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 6. A node may contain a value or a condition or represent a separate data structure or a tree of its own. Each node in a tree has zero or more child nodes , which are below it in the tree. nodes Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 7. The topmost node in a tree is called the root node . Being the topmost node, the root node will not have parents. It is the node at which operations on the tree commonly begin. root node Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 8. A node that has a child is called the parent node (or ancestor node , or superior ). Each node in tree has at most one parent except root node. parent node Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 9. A node that has a parent node is called the child node. Each node in tree has is child node except leaf node. parent node Child node Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 10. A node with no children is called a leaf node. Most leaf nodes are at the bottom most level of tree. Since they are at the bottom most level, they do not have any children. They are also referred to as terminal node. Leaf node Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 11. A subtree is a portion of a tree data structure that can be viewed as a complete tree in itself. Any node in a tree , together with all the nodes below it, comprise a subtree of . The subtree corresponding to the root node is the entire tree; the subtree corresponding to any other node is called is a proper subtree Sub-tree Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 12. An internal node or inner node is any node of a tree that has child nodes and is thus not a leaf node. An intermediate node between the root and the leaf nodes is called an internal node. Internal nodes Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 13. First we study a special kind of tree called Binary tree, which can easily maintained in the computer. Binary tree can be define as a finite set of elements, called nodes. A binary tree can be either empty or Each node has at most two children. Example:- Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC) A B D E C F
  • 14. Each node in binary tree is assigned a level number. The level of each node in binary tree is defined as: Root of tree is defined as level 0 Level number of other nodes is 1 more than level number of its father node or parent node. Example: A C B LEVEL 0 LEVEL 1 Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 15. The depth or height of tree is one more than the largest level number of tree. For example if the largest level number of tree is 2 than its depth is calculate by 2+1=3. Example: LEVEL 0 LEVEL 1 A B C In this example the largest level number is 1 therefore depth is 1+1=2 Depth=2 Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 16. Strictly Binary Tree: If every internal node (non terminal node) has its non empty left & right children then it is called strictly binary tree. Here every internal node A, B, E has two non empty left and right child hence it is strictly binary tree. A B C D E F G Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 17. Complete Binary Tree: A complete binary tree is a binary tree where all internal nodes have both children except the last node. In this tree the last node () has only one child. 3 1 2 4 5 6 Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 18. Extended Binary Tree: A binary tree is called extended binary tree if every node of tree has zero or two children. It is also said to be 2-tree. In binary tree, most of the nodes have one child then we can add one more child and can extend it. So it can be converted to extended binary tree. Extended binary tree Binary Tree Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC)
  • 19. Binary Search Tree: A binary search tree is a binary tree in which each node has value greater than every node of left sub-tree and less than every node of right sub-tree. Prepared by: Shumaila Bashir Sheikh(Lecturer, ITC) 50 45 22 48 75 85