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

What's hot

358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
sumitbardhan
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
Data Structures
Data StructuresData Structures
Data Structures
Prof. Dr. K. Adisesha
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
Keval Bhogayata
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
KristinaBorooah
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structuresMohd Arif
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
Data structure and its types.
Data structure and its types.Data structure and its types.
Data structure and its types.
buyinstagramfollowersaustralia
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
chauhankapil
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
Rameesha Sadaqat
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
Self-Employed
 
data structure
data structuredata structure
data structure
hashim102
 
Arrays
ArraysArrays
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 

What's hot (20)

358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Data Structures
Data StructuresData Structures
Data Structures
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
2D Array
2D Array 2D Array
2D Array
 
Linked list
Linked list Linked list
Linked list
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Data structure and its types.
Data structure and its types.Data structure and its types.
Data structure and its types.
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
 
data structure
data structuredata structure
data structure
 
Arrays
ArraysArrays
Arrays
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 

Similar to Chapter 8: tree data structure

DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptx
AryaMNair6
 
Trees - Data structures in C/Java
Trees - Data structures in C/JavaTrees - Data structures in C/Java
Trees - Data structures in C/Javageeksrik
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
ASairamSairam1
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentation
nakulvarshney371
 
Index Structures.pptx
Index Structures.pptxIndex Structures.pptx
Index Structures.pptx
MBablu1
 
Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)
pushpalathakrishnan
 
104333 sri vidhya eng notes
104333 sri vidhya eng notes104333 sri vidhya eng notes
104333 sri vidhya eng notes
Krishnakumar Btech
 
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
SIVAKUMARM603675
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
Daniyal Khan
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
SurajSharma266169
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptx
RahulAI
 
Bit by bit into data structures
Bit by bit into data structuresBit by bit into data structures
Bit by bit into data structures
Hridyesh Bisht
 
BINARY SEARCH TREE
BINARY SEARCH TREE BINARY SEARCH TREE
BINARY SEARCH TREE
Usha Mahalingam
 
Data structure tree - beginner
Data structure tree - beginnerData structure tree - beginner
Data structure tree - beginner
MD. MARUFUZZAMAN .
 
Unit 4.1 (tree)
Unit 4.1 (tree)Unit 4.1 (tree)
Unit 4.1 (tree)
DurgaDeviCbit
 
Data structures
Data structuresData structures
Data structures
Dr.MAYA NAYAK
 
ICS Part 2 Computer Science Short Notes
ICS Part 2 Computer Science Short NotesICS Part 2 Computer Science Short Notes
ICS Part 2 Computer Science Short Notes
Abdul Haseeb
 
Binary tree
Binary treeBinary tree
Binary tree
Maria Saleem
 

Similar to Chapter 8: tree data structure (20)

DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptx
 
Trees - Data structures in C/Java
Trees - Data structures in C/JavaTrees - Data structures in C/Java
Trees - Data structures in C/Java
 
Binary trees
Binary treesBinary trees
Binary trees
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentation
 
Index Structures.pptx
Index Structures.pptxIndex Structures.pptx
Index Structures.pptx
 
Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)
 
104333 sri vidhya eng notes
104333 sri vidhya eng notes104333 sri vidhya eng notes
104333 sri vidhya eng notes
 
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
 
Makalah if2091-2011-020
Makalah if2091-2011-020Makalah if2091-2011-020
Makalah if2091-2011-020
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptx
 
Bit by bit into data structures
Bit by bit into data structuresBit by bit into data structures
Bit by bit into data structures
 
BINARY SEARCH TREE
BINARY SEARCH TREE BINARY SEARCH TREE
BINARY SEARCH TREE
 
Data structure tree - beginner
Data structure tree - beginnerData structure tree - beginner
Data structure tree - beginner
 
Unit 4.1 (tree)
Unit 4.1 (tree)Unit 4.1 (tree)
Unit 4.1 (tree)
 
Data structures
Data structuresData structures
Data structures
 
ICS Part 2 Computer Science Short Notes
ICS Part 2 Computer Science Short NotesICS Part 2 Computer Science Short Notes
ICS Part 2 Computer Science Short Notes
 
Binary tree
Binary treeBinary tree
Binary tree
 

More from Mahmoud Alfarra

Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2
Mahmoud Alfarra
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using Java
Mahmoud Alfarra
 
Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structure
Mahmoud Alfarra
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
Mahmoud Alfarra
 
Chapter 7: Queue data structure
Chapter 7:  Queue data structureChapter 7:  Queue data structure
Chapter 7: Queue data structure
Mahmoud Alfarra
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structure
Mahmoud Alfarra
 
Chapter 5: linked list data structure
Chapter 5: linked list data structureChapter 5: linked list data structure
Chapter 5: linked list data structure
Mahmoud Alfarra
 
Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureChapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structure
Mahmoud Alfarra
 
Chapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureChapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structure
Mahmoud Alfarra
 
Chapter 2: array and array list data structure
Chapter 2: array and array list  data structureChapter 2: array and array list  data structure
Chapter 2: array and array list data structure
Mahmoud Alfarra
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter1  intro toprincipleofc#_datastructure_b_csChapter1  intro toprincipleofc#_datastructure_b_cs
Chapter1 intro toprincipleofc#_datastructure_b_cs
Mahmoud Alfarra
 
Chapter 0: introduction to data structure
Chapter 0: introduction to data structureChapter 0: introduction to data structure
Chapter 0: introduction to data structure
Mahmoud Alfarra
 
3 classification
3  classification3  classification
3 classification
Mahmoud Alfarra
 
8 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 201020118 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 20102011
Mahmoud Alfarra
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011
Mahmoud Alfarra
 
6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-
Mahmoud Alfarra
 
5 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop201020115 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop20102011
Mahmoud Alfarra
 
4 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava201020114 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava20102011
Mahmoud Alfarra
 
3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer
Mahmoud Alfarra
 
2 programming-using-java how to built application
2 programming-using-java how to built application2 programming-using-java how to built application
2 programming-using-java how to built application
Mahmoud Alfarra
 

More from Mahmoud Alfarra (20)

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

Recently uploaded

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.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