SlideShare uma empresa Scribd logo
1 de 28
PRESENTATION ON
Tree
in
Data Structure
1
DATA STRUCTURE
Store and organize data in computer.
Linear Data Structure
Arrays
Linked List
Stacks
Queues 2
LOGIC OF TREE
Used to represent hierarchica data.
Shuvo(CEO)
Shawon(CTO ) Tarun(Presedent)
Bithi Moni Sila Rashel Raj
Dola Shakila Riaj Shakib 3
Used to represent hierarchical data.
Shuvo(CEO)
Shawon(CTO ) Tarun(Presedent)
Bithi Moni Sila Rashel Raj
Dola Shakila Riaj Shakib 4
 A Collection of entities called Nodes.
 Tree is a Non-Linear Data Structure.
 It’s a hierarchica Structure.
TREE
Nodes
5
Root-The top most Node.
Children
Parents
Siblings- Have same parents.
Leaf- Has no Child.
RELATION OF TREE
1
3
2
4
6
5
8
7
11109
6
EDGES, DEPTH, HEIGHT
 Edges: If a tree have N nodes
It have N-1 edges.
 Depth of x: Length of path from
Root to x.
 Hight of x: No. Of edges in longest
Path from x to a leaf
Nodes
Leaf7
SOME APPLICATION OF TREE IN COMPUTER SCIENCE
1. Storing naturally hierarchicl data- File system.
2. Organige data for quick search, insertion, deletion- Binary search
tree.
3. Dictionary
4. Network Routing Algorithm.
8
Each node can have at most 2 childern.
A node have only left and right child or
Only left child or
Only right child.
A leaf node has no left or right child.
A leaf node has only NULL.
BINARY TREE
Root
Right- child
of root.
Left-child
of root
Leaf
NULL9
STRICT/PROPER BINARY TREE
Each node can have either
2 or 0 child
Root
10
COMPLETE BINARY TREE
 The last level is completely filled.
 All nodes are as left as possible.
Root
L-2
L-3
L-4
L-1
11
PARFECT BINARY TREE
All the levels are comletely filled.
Root
L-2
L-3
L-1
12
WE CAN IMPLEMENT BINARY TREE USING
A) Dynamically created nodes.
struct node
{
int data;
struct node* left;
struct node* right
}
2
4 6
13
OR
0 1 2 3 4 5 6
B) Arrays: It only works “complete Binary tree”.
For node at index i;
Left-child-index=2i+1
Right-child-index=2i+2
2 4 1 5 8 7 9
14
IMPLEMENT OF BINARY SEARCH TREE
Value of all the nodes in left subtree is Lesser or Equal.
Value of all the nodes in right subtree is greater.
Left-Subtree Right-Subtree
(Lesser) (Greater)
15
EXAMPLE
 15>10-Left
 15<20-Right
 10>8-Left
 10<12-Right
 20>17-Left
 20<25-Right
15
2010
12 258 17
Root
16
BINARY TREE TRAVERSAL
Tree traversal
Breadth-first or
Lever-order
F,D,J,B,E,G,K,A,C,I,H
Depth-first
Preorder, Inorder &
Postorder
F
JD
I
E KB G
A C
Root
H
17
PREORDER(DLR)
Data Left Right
<root><left><right>
F,D,B,A,C,E,J,G,I,H,K
Void Postorder(struct bstnode* root)
{
if(root==NULL)
Postorder(root->right);
Postordrt(root->right);
printf(“%c”,root->data);
}
F
JD
I
E KB G
A C
Root
H
18
INORDER(LDR)
Left Data Right
<left><root><right>
A,B,C,D,E,F,G,H,I,J,K
Void Inorder(struct bstnode* root)
{
if(root==NULL) return;
Inorder(root->left);
printf(“%c”,root->data);
Inorder(root->right);
}
F
JD
I
E KB G
A C
Root
H
19
POSTORDER(LRD)
Left Right Data
<left><right><root>
A,C,B,E,D,H,I,G,K,J,F,A,B
Void Postorder(struct bstnode* root)
{
if(root==NULL)
Postorder(root->right);
Postordrt(root->right);
printf(“%c”,root->data);
}
F
JD
I
E KB G
A C
Root
H
20
SEARCH AN ELEMENT IN BST
bool Search( bstnode* root, data type)
{
if (root==NULL) return false;
else if(root->data == data) return true;
else if(root->data <= data)
return Search(root->left, data);
else
return Search(root->right, data);
}
12
155
14
7 173 13
8 11
Root
21
DLELETE A NODE FROM BST
 There are three items to delete.
 Case 1: No Child
 Case 2: One Child
 Case 3: Two Child
12
155
14
7 173 13
8 11
Root
22
CASE 1: NO CHILD
 Remove to reference of the Node
 From it’s parent &
 Return NULL
12
155
14
7 173 13
8 11
Root
23
CASE 2: ONE CHILD
 Find the Node to Delete
 Link it’s parent to this only child.
 Remain attached to the tree.
12
155
14
7 173 13
8 11
Root
24
CASE 3: TWO CHILD
Two way to delete.
1.
Find minimum in right
Copy the value in targetted node
Delete duplicate from right subtree.
12
155
14
7 173 13
8 11
Root
25
CASE 3: TWO CHILD
2.
Find maximum in left
Copy the value in targetted node
Delete duplicate from left-subtree.
12
155
14
7 173 13
8 11
Root
26
RUNNING TIME OF OPERATION
Operation Array Link List Binary Search
Tree(average case)
Search(x)-Search
for an element x.
O(Log n) O(n) O(Log n)
Insertion(x)-Insert
an element x.
O(n) O(1) O(Log n)
Remove(x)-
Remove an
element x.
O(n) O(n) O(Log n)
27
28

Mais conteúdo relacionado

Mais procurados

SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Treekhabbab_h
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanDaniyal Khan
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structureMAHALAKSHMI P
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Treesagar yadav
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxAlbin562191
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary searchZia Ush Shamszaman
 

Mais procurados (20)

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
 
Linked list
Linked listLinked list
Linked list
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Arrays
ArraysArrays
Arrays
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 

Destaque (20)

Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Tree
TreeTree
Tree
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Tree
TreeTree
Tree
 
Lecture7 data structure(tree)
Lecture7 data structure(tree)Lecture7 data structure(tree)
Lecture7 data structure(tree)
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Binary tree
Binary treeBinary tree
Binary tree
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
data structure(tree operations)
data structure(tree operations)data structure(tree operations)
data structure(tree operations)
 
B Trees
B TreesB Trees
B Trees
 
Stack Data structure
Stack Data structureStack Data structure
Stack Data structure
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
B tree
B treeB tree
B tree
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 

Semelhante a Tree in data structure

Data structure tree - beginner
Data structure tree - beginnerData structure tree - beginner
Data structure tree - beginnerMD. MARUFUZZAMAN .
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediateMD. MARUFUZZAMAN .
 
17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversalIntro C# Book
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.pptSuneel61
 
Binary Search Tree Traversal.ppt
Binary Search Tree Traversal.pptBinary Search Tree Traversal.ppt
Binary Search Tree Traversal.pptRiannel Tecson
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like StructuresIntro C# Book
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations varagilavanya
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresAmrinder Arora
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .pptpoonamsngr
 
Trees in data structrures
Trees in data structruresTrees in data structrures
Trees in data structruresGaurav Sharma
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxAryaMNair6
 

Semelhante a Tree in data structure (20)

Data structure tree - beginner
Data structure tree - beginnerData structure tree - beginner
Data structure tree - beginner
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediate
 
Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
 
Binary tree
Binary treeBinary tree
Binary tree
 
Data Structures
Data StructuresData Structures
Data Structures
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.ppt
 
Binary Search Tree Traversal.ppt
Binary Search Tree Traversal.pptBinary Search Tree Traversal.ppt
Binary Search Tree Traversal.ppt
 
Binary Trees.ppt
Binary Trees.pptBinary Trees.ppt
Binary Trees.ppt
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like Structures
 
Trees
TreesTrees
Trees
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .ppt
 
Trees in data structrures
Trees in data structruresTrees in data structrures
Trees in data structrures
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
 
DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptx
 

Último

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Último (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

Tree in data structure

  • 2. DATA STRUCTURE Store and organize data in computer. Linear Data Structure Arrays Linked List Stacks Queues 2
  • 3. LOGIC OF TREE Used to represent hierarchica data. Shuvo(CEO) Shawon(CTO ) Tarun(Presedent) Bithi Moni Sila Rashel Raj Dola Shakila Riaj Shakib 3
  • 4. Used to represent hierarchical data. Shuvo(CEO) Shawon(CTO ) Tarun(Presedent) Bithi Moni Sila Rashel Raj Dola Shakila Riaj Shakib 4
  • 5.  A Collection of entities called Nodes.  Tree is a Non-Linear Data Structure.  It’s a hierarchica Structure. TREE Nodes 5
  • 6. Root-The top most Node. Children Parents Siblings- Have same parents. Leaf- Has no Child. RELATION OF TREE 1 3 2 4 6 5 8 7 11109 6
  • 7. EDGES, DEPTH, HEIGHT  Edges: If a tree have N nodes It have N-1 edges.  Depth of x: Length of path from Root to x.  Hight of x: No. Of edges in longest Path from x to a leaf Nodes Leaf7
  • 8. SOME APPLICATION OF TREE IN COMPUTER SCIENCE 1. Storing naturally hierarchicl data- File system. 2. Organige data for quick search, insertion, deletion- Binary search tree. 3. Dictionary 4. Network Routing Algorithm. 8
  • 9. Each node can have at most 2 childern. A node have only left and right child or Only left child or Only right child. A leaf node has no left or right child. A leaf node has only NULL. BINARY TREE Root Right- child of root. Left-child of root Leaf NULL9
  • 10. STRICT/PROPER BINARY TREE Each node can have either 2 or 0 child Root 10
  • 11. COMPLETE BINARY TREE  The last level is completely filled.  All nodes are as left as possible. Root L-2 L-3 L-4 L-1 11
  • 12. PARFECT BINARY TREE All the levels are comletely filled. Root L-2 L-3 L-1 12
  • 13. WE CAN IMPLEMENT BINARY TREE USING A) Dynamically created nodes. struct node { int data; struct node* left; struct node* right } 2 4 6 13
  • 14. OR 0 1 2 3 4 5 6 B) Arrays: It only works “complete Binary tree”. For node at index i; Left-child-index=2i+1 Right-child-index=2i+2 2 4 1 5 8 7 9 14
  • 15. IMPLEMENT OF BINARY SEARCH TREE Value of all the nodes in left subtree is Lesser or Equal. Value of all the nodes in right subtree is greater. Left-Subtree Right-Subtree (Lesser) (Greater) 15
  • 16. EXAMPLE  15>10-Left  15<20-Right  10>8-Left  10<12-Right  20>17-Left  20<25-Right 15 2010 12 258 17 Root 16
  • 17. BINARY TREE TRAVERSAL Tree traversal Breadth-first or Lever-order F,D,J,B,E,G,K,A,C,I,H Depth-first Preorder, Inorder & Postorder F JD I E KB G A C Root H 17
  • 18. PREORDER(DLR) Data Left Right <root><left><right> F,D,B,A,C,E,J,G,I,H,K Void Postorder(struct bstnode* root) { if(root==NULL) Postorder(root->right); Postordrt(root->right); printf(“%c”,root->data); } F JD I E KB G A C Root H 18
  • 19. INORDER(LDR) Left Data Right <left><root><right> A,B,C,D,E,F,G,H,I,J,K Void Inorder(struct bstnode* root) { if(root==NULL) return; Inorder(root->left); printf(“%c”,root->data); Inorder(root->right); } F JD I E KB G A C Root H 19
  • 20. POSTORDER(LRD) Left Right Data <left><right><root> A,C,B,E,D,H,I,G,K,J,F,A,B Void Postorder(struct bstnode* root) { if(root==NULL) Postorder(root->right); Postordrt(root->right); printf(“%c”,root->data); } F JD I E KB G A C Root H 20
  • 21. SEARCH AN ELEMENT IN BST bool Search( bstnode* root, data type) { if (root==NULL) return false; else if(root->data == data) return true; else if(root->data <= data) return Search(root->left, data); else return Search(root->right, data); } 12 155 14 7 173 13 8 11 Root 21
  • 22. DLELETE A NODE FROM BST  There are three items to delete.  Case 1: No Child  Case 2: One Child  Case 3: Two Child 12 155 14 7 173 13 8 11 Root 22
  • 23. CASE 1: NO CHILD  Remove to reference of the Node  From it’s parent &  Return NULL 12 155 14 7 173 13 8 11 Root 23
  • 24. CASE 2: ONE CHILD  Find the Node to Delete  Link it’s parent to this only child.  Remain attached to the tree. 12 155 14 7 173 13 8 11 Root 24
  • 25. CASE 3: TWO CHILD Two way to delete. 1. Find minimum in right Copy the value in targetted node Delete duplicate from right subtree. 12 155 14 7 173 13 8 11 Root 25
  • 26. CASE 3: TWO CHILD 2. Find maximum in left Copy the value in targetted node Delete duplicate from left-subtree. 12 155 14 7 173 13 8 11 Root 26
  • 27. RUNNING TIME OF OPERATION Operation Array Link List Binary Search Tree(average case) Search(x)-Search for an element x. O(Log n) O(n) O(Log n) Insertion(x)-Insert an element x. O(n) O(1) O(Log n) Remove(x)- Remove an element x. O(n) O(n) O(Log n) 27
  • 28. 28