3
Most read
5
Most read
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

PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
PPT
b+ tree
PPT
Binary search tree in data structures
PPTX
Tree in data structure
PPTX
VCE Unit 01 (2).pptx
PPT
Searching algorithms
PPTX
Binary Search Tree
PPTX
Linear and Binary search
Trees, Binary Search Tree, AVL Tree in Data Structures
b+ tree
Binary search tree in data structures
Tree in data structure
VCE Unit 01 (2).pptx
Searching algorithms
Binary Search Tree
Linear and Binary search

What's hot (20)

PPTX
trees in data structure
PDF
Expression trees
PPTX
Binomial heap presentation
PPT
1.5 binary search tree
PPTX
Trees in data structures
PPT
Operations on linked list
PPTX
VCE Unit 04vv.pptx
PPT
Abstract data types (adt) intro to data structure part 2
PPSX
Data Structure (Stack)
PPT
Avl tree
PPT
Binary search tree(bst)
PPTX
Heaptree
PPTX
Tree traversal techniques
PPTX
B+ tree intro,uses,insertion and deletion
PPTX
PPTX
Data Structures - Lecture 8 [Sorting Algorithms]
PPTX
AVL Tree in Data Structure
PPTX
Threaded Binary Tree.pptx
PPTX
single linked list
trees in data structure
Expression trees
Binomial heap presentation
1.5 binary search tree
Trees in data structures
Operations on linked list
VCE Unit 04vv.pptx
Abstract data types (adt) intro to data structure part 2
Data Structure (Stack)
Avl tree
Binary search tree(bst)
Heaptree
Tree traversal techniques
B+ tree intro,uses,insertion and deletion
Data Structures - Lecture 8 [Sorting Algorithms]
AVL Tree in Data Structure
Threaded Binary Tree.pptx
single linked list
Ad

Similar to Chapter 8: tree data structure (20)

PDF
Treeeeeeeeeeeeeeeeereeeeeeeeeeeeeeee.pdf
PPTX
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
PPTX
Introduction to Tree_Data Structure.pptx
PPTX
Binary tree
PPTX
BST.pptx this is Good for data structure
PPTX
BST.pptx this isp used for learning binary search trees
PPTX
tree-160731205832.pptx
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPT
Trees gt(1)
PPT
4.2 bst 03
PPTX
Unit 3 trees
PPT
Binary trees
PPTX
07-Lecture.pptxlkjslkjdfkjskljdflksj;fdkj
PPTX
Data structure tree- advance
PPTX
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
PPTX
Week 8 (trees)
PPTX
Data Structures using Python(generic elective).pptx
PDF
PPT
Lecture 5 tree.pptx
Treeeeeeeeeeeeeeeeereeeeeeeeeeeeeeee.pdf
BASIC TREE AND TYPES OF DI CONCEPTS.pptx
Introduction to Tree_Data Structure.pptx
Binary tree
BST.pptx this is Good for data structure
BST.pptx this isp used for learning binary search trees
tree-160731205832.pptx
UNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptx
Trees gt(1)
4.2 bst 03
Unit 3 trees
Binary trees
07-Lecture.pptxlkjslkjdfkjskljdflksj;fdkj
Data structure tree- advance
DS-UNIT-4zjufrusefihfacbciauhfbaiuhc.pptx
Week 8 (trees)
Data Structures using Python(generic elective).pptx
Lecture 5 tree.pptx
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
The 10 Most Inspiring Education Leaders to Follow in 2025.pdf
PPTX
Chapter-4-Rizal-Higher-Education-1-2_081545.pptx
PDF
3-Elementary-Education-Prototype-Syllabi-Compendium.pdf
DOCX
HELMET DETECTION AND BIOMETRIC BASED VEHICLESECURITY USING MACHINE LEARNING.docx
PDF
Global strategy and action plan on oral health 2023 - 2030.pdf
PDF
GSA-Past-Papers-2010-2024-2.pdf CSS examination
PPTX
UCSP Section A - Human Cultural Variations,Social Differences,social ChangeCo...
PPTX
Single Visit Endodontics.pptx treatment in one visit
PPTX
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
PPTX
climate change of delhi impacts on climate and there effects
PDF
HSE 2022-2023.pdf الصحه والسلامه هندسه نفط
PDF
FAMILY PLANNING (preventative and social medicine pdf)
PDF
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
PPTX
Ppt obs emergecy.pptxydirnbduejguxjjdjidjdbuc
PDF
Developing speaking skill_learning_mater.pdf
PPTX
Environmental Sciences and Sustainability Chapter 2
PDF
horaris de grups del curs 2025-2026 de l'institut
PDF
English 2nd semesteNotesh biology biopsy results from the other day and I jus...
PPTX
GW4 BioMed Candidate Support Webinar 2025
PDF
IS1343_2012...........................pdf
The 10 Most Inspiring Education Leaders to Follow in 2025.pdf
Chapter-4-Rizal-Higher-Education-1-2_081545.pptx
3-Elementary-Education-Prototype-Syllabi-Compendium.pdf
HELMET DETECTION AND BIOMETRIC BASED VEHICLESECURITY USING MACHINE LEARNING.docx
Global strategy and action plan on oral health 2023 - 2030.pdf
GSA-Past-Papers-2010-2024-2.pdf CSS examination
UCSP Section A - Human Cultural Variations,Social Differences,social ChangeCo...
Single Visit Endodontics.pptx treatment in one visit
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
climate change of delhi impacts on climate and there effects
HSE 2022-2023.pdf الصحه والسلامه هندسه نفط
FAMILY PLANNING (preventative and social medicine pdf)
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
Ppt obs emergecy.pptxydirnbduejguxjjdjidjdbuc
Developing speaking skill_learning_mater.pdf
Environmental Sciences and Sustainability Chapter 2
horaris de grups del curs 2025-2026 de l'institut
English 2nd semesteNotesh biology biopsy results from the other day and I jus...
GW4 BioMed Candidate Support Webinar 2025
IS1343_2012...........................pdf

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