SlideShare una empresa de Scribd logo
1 de 15
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

Más contenido relacionado

La actualidad más candente

Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structureIkhlas Rahman
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]DEEPIKA T
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
2 3 Trees Algorithm - Data Structure
2 3 Trees Algorithm - Data Structure2 3 Trees Algorithm - Data Structure
2 3 Trees Algorithm - Data StructureTish997
 
Database Normalization
Database NormalizationDatabase Normalization
Database NormalizationArun Sharma
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary treeKrish_ver2
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operationsKamran Zafar
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap treezia eagle
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked ListNinad Mankar
 
UNIT III NON LINEAR DATA STRUCTURES – TREES
UNIT III 	NON LINEAR DATA STRUCTURES – TREESUNIT III 	NON LINEAR DATA STRUCTURES – TREES
UNIT III NON LINEAR DATA STRUCTURES – TREESKathirvel Ayyaswamy
 
7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Depth First Search ( DFS )
Depth First Search ( DFS )Depth First Search ( DFS )
Depth First Search ( DFS )Sazzad Hossain
 

La actualidad más candente (20)

Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Red black tree
Red black treeRed black tree
Red black tree
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
2-3 Tree
2-3 Tree2-3 Tree
2-3 Tree
 
2 3 Trees Algorithm - Data Structure
2 3 Trees Algorithm - Data Structure2 3 Trees Algorithm - Data Structure
2 3 Trees Algorithm - Data Structure
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
UNIT III NON LINEAR DATA STRUCTURES – TREES
UNIT III 	NON LINEAR DATA STRUCTURES – TREESUNIT III 	NON LINEAR DATA STRUCTURES – TREES
UNIT III NON LINEAR DATA STRUCTURES – TREES
 
7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil
 
Depth First Search ( DFS )
Depth First Search ( DFS )Depth First Search ( DFS )
Depth First Search ( DFS )
 

Similar a Chapter 8: tree data structure

DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxAryaMNair6
 
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 structuresASairamSairam1
 
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 presentationnakulvarshney371
 
Index Structures.pptx
Index Structures.pptxIndex Structures.pptx
Index Structures.pptxMBablu1
 
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
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanDaniyal Khan
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptxRahulAI
 
Bit by bit into data structures
Bit by bit into data structuresBit by bit into data structures
Bit by bit into data structuresHridyesh Bisht
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
Data structure tree - beginner
Data structure tree - beginnerData structure tree - beginner
Data structure tree - beginnerMD. MARUFUZZAMAN .
 
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 NotesAbdul Haseeb
 

Similar a 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
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
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
 

Más de 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 2Mahmoud Alfarra
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using JavaMahmoud Alfarra
 
Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structureMahmoud Alfarra
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structureMahmoud Alfarra
 
Chapter 7: Queue data structure
Chapter 7:  Queue data structureChapter 7:  Queue data structure
Chapter 7: Queue data structureMahmoud Alfarra
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structureMahmoud Alfarra
 
Chapter 5: linked list data structure
Chapter 5: linked list data structureChapter 5: linked list data structure
Chapter 5: linked list data structureMahmoud 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 structureMahmoud 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 structureMahmoud 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 structureMahmoud Alfarra
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter1  intro toprincipleofc#_datastructure_b_csChapter1  intro toprincipleofc#_datastructure_b_cs
Chapter1 intro toprincipleofc#_datastructure_b_csMahmoud Alfarra
 
Chapter 0: introduction to data structure
Chapter 0: introduction to data structureChapter 0: introduction to data structure
Chapter 0: introduction to data structureMahmoud 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 20102011Mahmoud Alfarra
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011Mahmoud 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-tooop20102011Mahmoud Alfarra
 
4 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava201020114 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava20102011Mahmoud 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 computerMahmoud 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 applicationMahmoud Alfarra
 

Más de 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
 

Último

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Último (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

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