SlideShare a Scribd company logo
DATA STRUCTURE
Chapter 8: Tree & binary tree
Prepared & Presented by
Mr. Mahmoud R. Alfarra
2011-2012
College of Science & Technology
Dep. Of Computer Science & IT
BCs of Information Technology
http://mfarra.cst.ps
Out Line
 What we mean by a tree?
 Parts of tree
 Binary tree
 Binary search tree
 Building a Binary Search Tree
2
What we mean by a tree?
3
 Trees are a very common data structure in
computer science.
 A tree is a nonlinear data structure that is used
to store data in a hierarchical manner.
What we mean by a tree?
4
 A tree is a set of nodes connected by edges.
 Each box is a node and the lines connecting
the boxes are the edges.
 The nodes, obviously,
represent the entities
(people) that make up an
organization.
 The edges represent the
relationship between the
entities.
Parts of tree
5
Parts of tree
6
 The top node of a tree is called the root node.
 If a node is connected to other nodes below it,
the top node is called the parent, and the
nodes below it are called the parent’s
children.
 A node without any child node is called a leaf.
 The series of edges you follow to get from one
node to another is called a path.
 Visiting all the nodes in a tree in some
particular order is known as a tree
transversal.
Parts of tree
7
 A tree can be broken down into levels.
 A node at any level is considered the root of a
subtree, which consists of that root node’s
children, its children’s children, and so on.
 We can define the depth of a tree as the
number of layers in the tree.
 Finally, each node in a tree has a value. This
value is sometimes referred to as the key
value.
Binary tree
8
 A binary tree is defined as a tree where each
node can have no more than two children.
 By limiting the number of children to 2, we can
write efficient programs for inserting data,
deleting data, and searching for data in a
binary tree.
 The child nodes of a parent node are referred
to as the left node and the right node.
5
10
45
2 25 30
Binary search tree
9
 The binary search tree is a binary tree where
data with lesser values are stored in left
nodes and values with greater values are
stored in right nodes.
 This property provides for very efficient
searches.
Binary search tree
10
Binary
search trees
Not a binary
search tree
5
10
30
2 25 45
5
10
45
2 25 30
5
10
30
2
25
45
Building a Binary Search Tree
11
 A binary search tree is made up of nodes, so
we need a Node class that is similar to the
Node class we used in the linked list
implementation.
Building a Binary Search Tree
12
 Next we’re ready to build a BinarySearchTree
(BST) class.
 The class consists of just one data member- a
Node object that represents the root node of
the BST.
Building a Binary
Search Tree
Thank You …
14
Remember that: question is the key of knowledge
Ahl Eljanna 

‫ف‬ِ ‫نا‬‫ن‬‫ن‬‫ن‬َ‫ن‬ َ ‫ف‬ِ‫ن‬‫ن‬‫ن‬‫ن‬‫ن‬ََِ
َّ‫ف‬َ
َ‫نا‬‫ن‬‫ن‬‫ن‬َ
‫ب‬َ
‫فر‬َ
‫نام‬‫ن‬‫ن‬‫ن‬َ
َ‫ف‬‫ا‬
َ‫ن‬‫ن‬‫ن‬‫ن‬َ
‫م‬ِ‫ل‬َ
‫و‬
)::(
‫ف‬
‫ن‬ََِ
َّ‫ف‬ِ
َ َِ‫ف‬‫ن‬ِ
‫َآ‬ِّ‫ن‬‫ن‬‫ن‬‫ن‬ِ‫ب‬َ‫ف‬
‫ناف‬‫ن‬‫ن‬‫ن‬َ
‫م‬ُ
‫ك‬
‫ف‬ِ
َ
‫َب‬‫ن‬
ِ
‫ذ‬َ
‫ك‬ُ‫ت‬
)::(
‫ف‬ ‫نا‬َ‫ا‬
‫ن‬‫ف‬َ‫أ‬‫ىف‬َ‫ت‬‫ا‬َ
‫و‬َ‫ذ‬
)::(
‫ف‬
َ‫ف‬
‫ف‬ُ
‫ك‬‫ن‬ََِ
َّ‫ف‬ِ
َ َِ‫ف‬‫ن‬ِ
‫َآ‬ِّ‫ن‬ِ‫ب‬
‫ف‬ِ
َ
‫َب‬‫ن‬
ِ
‫نذ‬َ
‫ك‬ُ‫ت‬‫ناف‬َ
‫م‬
)::(
‫ف‬ِ
َِ‫ن‬‫ن‬‫ا‬َ
ِ‫ف‬ِ ‫نا‬‫ن‬َ‫ا‬
‫ن‬‫ي‬َ
‫نافي‬‫ن‬َ
‫م‬ِ
‫ه‬‫ي‬ِ‫ف‬
)::(
‫ف‬
َ‫ف‬
‫ن‬‫ن‬َ
‫م‬ُ
‫ك‬‫ن‬ََِ
َّ‫ف‬ِ
َ َِ‫ف‬‫ن‬ِ
‫َآ‬ِّ‫ن‬‫ن‬ِ‫ب‬
‫ف‬ِ
َ
‫َب‬‫ن‬
ِ
‫نذ‬‫ن‬َ
‫ك‬ُ‫ت‬‫اف‬
)::(
‫ن‬‫ن‬َ ‫ا‬
‫و‬َ‫ف‬ ‫ن‬‫ن‬َ
‫ه‬ِِّ‫ا‬َ‫ف‬‫ف‬‫ن‬ِ
‫نا‬‫ن‬ُ
ِّ‫ف‬‫ا‬
َ‫ن‬‫ن‬ِ
‫نافر‬‫ن‬َ
‫م‬ِ
‫ه‬‫ي‬ِ‫ف‬
‫ف‬ِ ‫ا‬
)::(
‫ف‬
‫ن‬ََِ
َّ‫ف‬ِ
َ َِ‫ف‬‫ن‬ِ
‫َآ‬ِّ‫ن‬‫ن‬ِ‫ب‬َ‫ف‬
‫ناف‬‫ن‬َ
‫م‬ُ
‫ك‬
‫ف‬ِ
َ
‫َب‬‫ن‬
ِ
‫نذ‬‫ن‬‫ن‬َ
‫ك‬ُ‫ت‬
)::(
‫ن‬‫ن‬‫ن‬ُ
‫ن‬‫ف‬‫نىف‬‫ن‬‫ن‬ََ
‫في‬َ
‫نع‬‫ن‬‫ن‬ِ‫ئ‬ِ
‫ك‬ ُ
‫ر‬
‫ن‬‫ن‬‫ن‬‫ا‬ ِ‫ف‬‫ا‬
َ‫ن‬‫ن‬‫ن‬ِ
‫نافر‬‫ن‬‫ن‬َ
‫ه‬ُ
‫ن‬ ِ‫ائ‬َ‫ط‬ََ‫ف‬‫ش‬ُ
‫ف‬‫ق‬َ‫ا‬
‫ن‬‫ب‬َ
‫ن‬
‫ف‬ ‫ا‬َ
‫فد‬ِ‫ا‬
‫ع‬َ
‫ن‬ ‫ن‬َ‫ا‬
‫ْل‬‫فا‬ َ
‫َن‬َ َ
‫و‬
)::(
15

More Related Content

PPTX
B and B+ tree
PDF
Data structure
PPT
Binary search tree in data structures
PPTX
Binary Search Tree
PPT
Lec 17 heap data structure
PPTX
Bubble sort | Data structure |
PPTX
B+ tree intro,uses,insertion and deletion
PPT
B trees in Data Structure
B and B+ tree
Data structure
Binary search tree in data structures
Binary Search Tree
Lec 17 heap data structure
Bubble sort | Data structure |
B+ tree intro,uses,insertion and deletion
B trees in Data Structure

What's hot (20)

PPTX
Binary Search Tree
PPTX
Data structure and its types
PPT
3.9 external sorting
PPTX
Data structures - unit 1
PPT
b+ tree
PPTX
Stack & Queue using Linked List in Data Structure
PPTX
Binary Tree in Data Structure
PPSX
Data Structure (Queue)
PPTX
Directory structure
PPTX
Data Structures - Lecture 8 [Sorting Algorithms]
PPTX
Queue - Data Structure - Notes
PDF
DSA Lab Manual C Scheme.pdf
PPTX
DMBS Indexes.pptx
PPTX
Binary search tree
PPTX
Data Structures - Lecture 7 [Linked List]
PPT
Linked List
PPTX
Data structures trees - B Tree & B+Tree.pptx
PPTX
Tree - Data Structure
PPT
Trees - Non Linear Data Structure
PPT
Queue data structure
Binary Search Tree
Data structure and its types
3.9 external sorting
Data structures - unit 1
b+ tree
Stack & Queue using Linked List in Data Structure
Binary Tree in Data Structure
Data Structure (Queue)
Directory structure
Data Structures - Lecture 8 [Sorting Algorithms]
Queue - Data Structure - Notes
DSA Lab Manual C Scheme.pdf
DMBS Indexes.pptx
Binary search tree
Data Structures - Lecture 7 [Linked List]
Linked List
Data structures trees - B Tree & B+Tree.pptx
Tree - Data Structure
Trees - Non Linear Data Structure
Queue data structure
Ad

Similar to Chapter 8: tree data structure (20)

PPTX
TREE PRESENTATION COMPUTER SCIENCE/DATA STRUCTURE
PPTX
Data Structures -Non Linear DS-Basics ofTrees
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPTX
TREES basics simple introduction .pptx
PPTX
TREES 1.pptx
PPTX
Understanding Tree Data Structure and Its Applications
PPTX
DATA STUCTURES-TREES.pptx
PPTX
Introduction-to-Trees-in-Data-Structures-and-Algorithms[1].pptx
DOCX
data structures Unit 3 notes.docxdata structures Unit 3 notes.docx
PPT
Trees - Data structures in C/Java
PPT
data structures and algorithms dsa engg.ppt
PPTX
Data Structure of computer science and technology
PDF
Binary trees
PPTX
Tree Data Structure in Advanced Data Structure
PPTX
Trees — Tree Terminology – Binary Trees – Binary Search Trees – Tree Traversa...
PPTX
Trees in data structures
PPT
Final tree.ppt tells about tree presentation
PPTX
Index Structures.pptx
DOCX
Data Structure Question Bank(2 marks)
TREE PRESENTATION COMPUTER SCIENCE/DATA STRUCTURE
Data Structures -Non Linear DS-Basics ofTrees
UNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptx
TREES basics simple introduction .pptx
TREES 1.pptx
Understanding Tree Data Structure and Its Applications
DATA STUCTURES-TREES.pptx
Introduction-to-Trees-in-Data-Structures-and-Algorithms[1].pptx
data structures Unit 3 notes.docxdata structures Unit 3 notes.docx
Trees - Data structures in C/Java
data structures and algorithms dsa engg.ppt
Data Structure of computer science and technology
Binary trees
Tree Data Structure in Advanced Data Structure
Trees — Tree Terminology – Binary Trees – Binary Search Trees – Tree Traversa...
Trees in data structures
Final tree.ppt tells about tree presentation
Index Structures.pptx
Data Structure Question Bank(2 marks)
Ad

More from Mahmoud Alfarra (20)

PPT
Computer Programming, Loops using Java - part 2
PPT
Computer Programming, Loops using Java
PPT
Chapter 10: hashing data structure
PPT
Chapter9 graph data structure
PPT
Chapter 7: Queue data structure
PPT
Chapter 6: stack data structure
PPT
Chapter 5: linked list data structure
PPT
Chapter 4: basic search algorithms data structure
PPT
Chapter 3: basic sorting algorithms data structure
PPT
Chapter 2: array and array list data structure
PPT
Chapter1 intro toprincipleofc#_datastructure_b_cs
PPT
Chapter 0: introduction to data structure
PPTX
3 classification
PPT
8 programming-using-java decision-making practices 20102011
PPT
7 programming-using-java decision-making220102011
PPT
6 programming-using-java decision-making20102011-
PPT
5 programming-using-java intro-tooop20102011
PPT
4 programming-using-java intro-tojava20102011
PPT
3 programming-using-java introduction-to computer
PPT
2 programming-using-java how to built application
Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java
Chapter 10: hashing data structure
Chapter9 graph data structure
Chapter 7: Queue data structure
Chapter 6: stack data structure
Chapter 5: linked list data structure
Chapter 4: basic search algorithms data structure
Chapter 3: basic sorting algorithms data structure
Chapter 2: array and array list data structure
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter 0: introduction to data structure
3 classification
8 programming-using-java decision-making practices 20102011
7 programming-using-java decision-making220102011
6 programming-using-java decision-making20102011-
5 programming-using-java intro-tooop20102011
4 programming-using-java intro-tojava20102011
3 programming-using-java introduction-to computer
2 programming-using-java how to built application

Recently uploaded (20)

PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Module 3: Health Systems Tutorial Slides S2 2025
Open Quiz Monsoon Mind Game Prelims.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O7-L3 Supply Chain Operations - ICLT Program
Anesthesia in Laparoscopic Surgery in India
Open folder Downloads.pdf yes yes ges yes
human mycosis Human fungal infections are called human mycosis..pptx
Cardiovascular Pharmacology for pharmacy students.pptx
How to Manage Starshipit in Odoo 18 - Odoo Slides
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
Insiders guide to clinical Medicine.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Chapter 8: tree data structure

  • 1. DATA STRUCTURE Chapter 8: Tree & binary tree Prepared & Presented by Mr. Mahmoud R. Alfarra 2011-2012 College of Science & Technology Dep. Of Computer Science & IT BCs of Information Technology http://mfarra.cst.ps
  • 2. Out Line  What we mean by a tree?  Parts of tree  Binary tree  Binary search tree  Building a Binary Search Tree 2
  • 3. What we mean by a tree? 3  Trees are a very common data structure in computer science.  A tree is a nonlinear data structure that is used to store data in a hierarchical manner.
  • 4. What we mean by a tree? 4  A tree is a set of nodes connected by edges.  Each box is a node and the lines connecting the boxes are the edges.  The nodes, obviously, represent the entities (people) that make up an organization.  The edges represent the relationship between the entities.
  • 6. Parts of tree 6  The top node of a tree is called the root node.  If a node is connected to other nodes below it, the top node is called the parent, and the nodes below it are called the parent’s children.  A node without any child node is called a leaf.  The series of edges you follow to get from one node to another is called a path.  Visiting all the nodes in a tree in some particular order is known as a tree transversal.
  • 7. Parts of tree 7  A tree can be broken down into levels.  A node at any level is considered the root of a subtree, which consists of that root node’s children, its children’s children, and so on.  We can define the depth of a tree as the number of layers in the tree.  Finally, each node in a tree has a value. This value is sometimes referred to as the key value.
  • 8. Binary tree 8  A binary tree is defined as a tree where each node can have no more than two children.  By limiting the number of children to 2, we can write efficient programs for inserting data, deleting data, and searching for data in a binary tree.  The child nodes of a parent node are referred to as the left node and the right node. 5 10 45 2 25 30
  • 9. Binary search tree 9  The binary search tree is a binary tree where data with lesser values are stored in left nodes and values with greater values are stored in right nodes.  This property provides for very efficient searches.
  • 10. Binary search tree 10 Binary search trees Not a binary search tree 5 10 30 2 25 45 5 10 45 2 25 30 5 10 30 2 25 45
  • 11. Building a Binary Search Tree 11  A binary search tree is made up of nodes, so we need a Node class that is similar to the Node class we used in the linked list implementation.
  • 12. Building a Binary Search Tree 12  Next we’re ready to build a BinarySearchTree (BST) class.  The class consists of just one data member- a Node object that represents the root node of the BST.
  • 14. Thank You … 14 Remember that: question is the key of knowledge
  • 15. Ahl Eljanna   ‫ف‬ِ ‫نا‬‫ن‬‫ن‬‫ن‬َ‫ن‬ َ ‫ف‬ِ‫ن‬‫ن‬‫ن‬‫ن‬‫ن‬ََِ َّ‫ف‬َ َ‫نا‬‫ن‬‫ن‬‫ن‬َ ‫ب‬َ ‫فر‬َ ‫نام‬‫ن‬‫ن‬‫ن‬َ َ‫ف‬‫ا‬ َ‫ن‬‫ن‬‫ن‬‫ن‬َ ‫م‬ِ‫ل‬َ ‫و‬ )::( ‫ف‬ ‫ن‬ََِ َّ‫ف‬ِ َ َِ‫ف‬‫ن‬ِ ‫َآ‬ِّ‫ن‬‫ن‬‫ن‬‫ن‬ِ‫ب‬َ‫ف‬ ‫ناف‬‫ن‬‫ن‬‫ن‬َ ‫م‬ُ ‫ك‬ ‫ف‬ِ َ ‫َب‬‫ن‬ ِ ‫ذ‬َ ‫ك‬ُ‫ت‬ )::( ‫ف‬ ‫نا‬َ‫ا‬ ‫ن‬‫ف‬َ‫أ‬‫ىف‬َ‫ت‬‫ا‬َ ‫و‬َ‫ذ‬ )::( ‫ف‬ َ‫ف‬ ‫ف‬ُ ‫ك‬‫ن‬ََِ َّ‫ف‬ِ َ َِ‫ف‬‫ن‬ِ ‫َآ‬ِّ‫ن‬ِ‫ب‬ ‫ف‬ِ َ ‫َب‬‫ن‬ ِ ‫نذ‬َ ‫ك‬ُ‫ت‬‫ناف‬َ ‫م‬ )::( ‫ف‬ِ َِ‫ن‬‫ن‬‫ا‬َ ِ‫ف‬ِ ‫نا‬‫ن‬َ‫ا‬ ‫ن‬‫ي‬َ ‫نافي‬‫ن‬َ ‫م‬ِ ‫ه‬‫ي‬ِ‫ف‬ )::( ‫ف‬ َ‫ف‬ ‫ن‬‫ن‬َ ‫م‬ُ ‫ك‬‫ن‬ََِ َّ‫ف‬ِ َ َِ‫ف‬‫ن‬ِ ‫َآ‬ِّ‫ن‬‫ن‬ِ‫ب‬ ‫ف‬ِ َ ‫َب‬‫ن‬ ِ ‫نذ‬‫ن‬َ ‫ك‬ُ‫ت‬‫اف‬ )::( ‫ن‬‫ن‬َ ‫ا‬ ‫و‬َ‫ف‬ ‫ن‬‫ن‬َ ‫ه‬ِِّ‫ا‬َ‫ف‬‫ف‬‫ن‬ِ ‫نا‬‫ن‬ُ ِّ‫ف‬‫ا‬ َ‫ن‬‫ن‬ِ ‫نافر‬‫ن‬َ ‫م‬ِ ‫ه‬‫ي‬ِ‫ف‬ ‫ف‬ِ ‫ا‬ )::( ‫ف‬ ‫ن‬ََِ َّ‫ف‬ِ َ َِ‫ف‬‫ن‬ِ ‫َآ‬ِّ‫ن‬‫ن‬ِ‫ب‬َ‫ف‬ ‫ناف‬‫ن‬َ ‫م‬ُ ‫ك‬ ‫ف‬ِ َ ‫َب‬‫ن‬ ِ ‫نذ‬‫ن‬‫ن‬َ ‫ك‬ُ‫ت‬ )::( ‫ن‬‫ن‬‫ن‬ُ ‫ن‬‫ف‬‫نىف‬‫ن‬‫ن‬ََ ‫في‬َ ‫نع‬‫ن‬‫ن‬ِ‫ئ‬ِ ‫ك‬ ُ ‫ر‬ ‫ن‬‫ن‬‫ن‬‫ا‬ ِ‫ف‬‫ا‬ َ‫ن‬‫ن‬‫ن‬ِ ‫نافر‬‫ن‬‫ن‬َ ‫ه‬ُ ‫ن‬ ِ‫ائ‬َ‫ط‬ََ‫ف‬‫ش‬ُ ‫ف‬‫ق‬َ‫ا‬ ‫ن‬‫ب‬َ ‫ن‬ ‫ف‬ ‫ا‬َ ‫فد‬ِ‫ا‬ ‫ع‬َ ‫ن‬ ‫ن‬َ‫ا‬ ‫ْل‬‫فا‬ َ ‫َن‬َ َ ‫و‬ )::( 15