SlideShare a Scribd company logo
1 of 13
Trees
Tree traversal
By : Dana Dia’a
Data structure and algorithms
Tree (ADT)
 What is a tree ?
 A set of nodes.
 Each node can have one or more children .
 Each node can have at most one parent.
Root
( no parent)
Leaves
( no child)
Node level
1
2
3
4
Binary tree
 In binary tree , each node has at most two children .
 In other word , it can have zero children ( empty ) , one or
two children but not more than two children .
 Examples of a binary trees :
binary search tree ( BSTree)
 Every node entry has a unique key ( keys are not the
same in the tree ) .
 All the keys in the left of a node are less than the key of
a node
 All the keys in the right of a node are greater than the
key of a node .
 Example of a BStree :
Left
Less than 8
Right
Greater than 8
A binary tree but NOT binary search
tree
Search a node
 A binary search tree provide an excellent structure for
searching a node .
 For example : find the node with value 6 .
 We compare: 6 is <or > 8( the root) ?
 6 is less than 8 so we go to the left of node .
 Then we compare : 6 is <or > 3 ?
 6 is greater than 3 so we go right to
The right of node .
 6 is found .
Tree traversal
 The process of visiting all nodes in a tree only
one time .
 Two classes :
 1 . Breadth – first traversal .
 2 . Depth –first traversal .
Breadth – first traversal
 We can go with two methods :
1. Visiting each node starting from the lowest level (
root ) and moving down level by level , visiting
each node from left to right . ( top – down – from
left – to right ) .
Output : 8 , 3 , 10 ,1 ,6 ,14 ,4 ,7
,13
Starts
Breadth – first traversal (cont.)
 The other method is :
1. Visiting each node starting from the highest level (
leaves ) and moving up level by level , visiting each
node from right to left . ( bottom – up – from right –
to left ) .
Starts
Output : 13 , 7 ,4 , 14 ,6 ,1 ,10 ,3 ,8
Depth – first traversal
 We have to consider three tasks in this type .
 V – visiting a node .
 L – traversing the left sub-tree if any .
 R – traversing the right sub-tree if any .
 There are six types of depth –first traversal , but
we will consider three of them :
 VLR ( Preorder )
 LVR ( Inorder )
 LRV ( Postorder)
VLR ( Preorder )
VLR
VLR VLR
VLRVLR VLR
VLR
VLR
VLR
Output : 8 ,3 ,1 ,6 ,4 ,7 ,10 ,14 ,13
Assuming that the
visit(v) is to output
the value
LVR ( Ineorder )
LVR
Output : 1 , 3 , 4 , 6 , 7 , 8 ,10 ,13 ,14
Assuming that the
visit() is to output
the valueLVR
LVR
LVR
LVR
LVR
LVR
LVRLVR
LRV ( Posteorder )
LRV
Output : 1 , 4 , 7 ,6 ,3 , 13 , 14 , 10 , 8
Assuming that the
visit() is to output
the value
LRV
LRV LRV
LRV
LRV
LRVLRVLRV

More Related Content

What's hot

Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
Selection sort
Selection sortSelection sort
Selection sortstella D
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structureVrushali Dhanokar
 
Stack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data StructureStack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data StructureMeghaj Mallick
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure Janki Shah
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search treeKrish_ver2
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsShubham Sharma
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Application of Data structure
Application of Data structureApplication of Data structure
Application of Data structureDeepika051991
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 

What's hot (20)

Tree and graph
Tree and graphTree and graph
Tree and graph
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Selection sort
Selection sortSelection sort
Selection sort
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structure
 
Stack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data StructureStack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data Structure
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Application of Data structure
Application of Data structureApplication of Data structure
Application of Data structure
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
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
Data structureData structure
Data structure
 

Viewers also liked

computer notes - Traversal of a binary tree
computer notes - Traversal of a binary treecomputer notes - Traversal of a binary tree
computer notes - Traversal of a binary treeecomputernotes
 
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)raj upadhyay
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
sorting algorithm graphical method
sorting algorithm graphical method sorting algorithm graphical method
sorting algorithm graphical method Shantanu Mishra
 
Deloitte uk-cpo-survey-2014
Deloitte uk-cpo-survey-2014Deloitte uk-cpo-survey-2014
Deloitte uk-cpo-survey-2014Clive Gallery
 
Phrasal verbs vaughan
Phrasal verbs  vaughanPhrasal verbs  vaughan
Phrasal verbs vaughanlola macias
 
Selectivitat writing guide2
Selectivitat writing guide2Selectivitat writing guide2
Selectivitat writing guide2lola macias
 
KEEP IT SAFE FINAL IT Security A6 FINAL 2 (1)
KEEP IT SAFE FINAL IT Security A6 FINAL 2 (1)KEEP IT SAFE FINAL IT Security A6 FINAL 2 (1)
KEEP IT SAFE FINAL IT Security A6 FINAL 2 (1)Jenine Sanchez
 
ми всі майбутні таланти
ми всі майбутні талантими всі майбутні таланти
ми всі майбутні талантиJohn_Fikus
 
Fact Sheet_FederalAgency-Aug2016-FINAL
Fact Sheet_FederalAgency-Aug2016-FINALFact Sheet_FederalAgency-Aug2016-FINAL
Fact Sheet_FederalAgency-Aug2016-FINALAnn Warner
 
Khodiyar ceramics (i) pvt ltd corporate presentation
Khodiyar ceramics (i) pvt ltd corporate presentationKhodiyar ceramics (i) pvt ltd corporate presentation
Khodiyar ceramics (i) pvt ltd corporate presentationNakul Bhut
 
Question 1 x2
Question 1 x2Question 1 x2
Question 1 x2Kirsty98
 

Viewers also liked (20)

Binary tree
Binary  treeBinary  tree
Binary tree
 
Unit8 C
Unit8 CUnit8 C
Unit8 C
 
Tree
TreeTree
Tree
 
computer notes - Traversal of a binary tree
computer notes - Traversal of a binary treecomputer notes - Traversal of a binary tree
computer notes - Traversal of a binary tree
 
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 
4.2 bst
4.2 bst4.2 bst
4.2 bst
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Binary Search Algorithm
Binary Search Algorithm Binary Search Algorithm
Binary Search Algorithm
 
sorting algorithm graphical method
sorting algorithm graphical method sorting algorithm graphical method
sorting algorithm graphical method
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Deloitte uk-cpo-survey-2014
Deloitte uk-cpo-survey-2014Deloitte uk-cpo-survey-2014
Deloitte uk-cpo-survey-2014
 
Phrasal verbs vaughan
Phrasal verbs  vaughanPhrasal verbs  vaughan
Phrasal verbs vaughan
 
Selectivitat writing guide2
Selectivitat writing guide2Selectivitat writing guide2
Selectivitat writing guide2
 
KEEP IT SAFE FINAL IT Security A6 FINAL 2 (1)
KEEP IT SAFE FINAL IT Security A6 FINAL 2 (1)KEEP IT SAFE FINAL IT Security A6 FINAL 2 (1)
KEEP IT SAFE FINAL IT Security A6 FINAL 2 (1)
 
Proposal
ProposalProposal
Proposal
 
ми всі майбутні таланти
ми всі майбутні талантими всі майбутні таланти
ми всі майбутні таланти
 
Fact Sheet_FederalAgency-Aug2016-FINAL
Fact Sheet_FederalAgency-Aug2016-FINALFact Sheet_FederalAgency-Aug2016-FINAL
Fact Sheet_FederalAgency-Aug2016-FINAL
 
Khodiyar ceramics (i) pvt ltd corporate presentation
Khodiyar ceramics (i) pvt ltd corporate presentationKhodiyar ceramics (i) pvt ltd corporate presentation
Khodiyar ceramics (i) pvt ltd corporate presentation
 
Question 1 x2
Question 1 x2Question 1 x2
Question 1 x2
 

Similar to Tree data structure

Similar to Tree data structure (20)

Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 
Tree data structure.pptx
Tree data structure.pptxTree data structure.pptx
Tree data structure.pptx
 
Biary search Tree.docx
Biary search Tree.docxBiary search Tree.docx
Biary search Tree.docx
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
4a searching-more
4a searching-more4a searching-more
4a searching-more
 
Binary trees
Binary treesBinary trees
Binary trees
 
Tree data structure
Tree data structureTree data structure
Tree data structure
 
Trees ayaz
Trees ayazTrees ayaz
Trees ayaz
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Trees
TreesTrees
Trees
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Tree
TreeTree
Tree
 

More from Dana dia

types of computer cases
types of computer cases types of computer cases
types of computer cases Dana dia
 
summarize system analysis and design ch2
summarize system analysis and design ch2 summarize system analysis and design ch2
summarize system analysis and design ch2 Dana dia
 
system analysis and design chapter 1 Kendall & Kendall
system analysis and design chapter 1 Kendall & Kendallsystem analysis and design chapter 1 Kendall & Kendall
system analysis and design chapter 1 Kendall & KendallDana dia
 
Os examples scheduling
Os examples schedulingOs examples scheduling
Os examples schedulingDana dia
 
Multicore system
Multicore systemMulticore system
Multicore systemDana dia
 
Multimedia
MultimediaMultimedia
MultimediaDana dia
 

More from Dana dia (6)

types of computer cases
types of computer cases types of computer cases
types of computer cases
 
summarize system analysis and design ch2
summarize system analysis and design ch2 summarize system analysis and design ch2
summarize system analysis and design ch2
 
system analysis and design chapter 1 Kendall & Kendall
system analysis and design chapter 1 Kendall & Kendallsystem analysis and design chapter 1 Kendall & Kendall
system analysis and design chapter 1 Kendall & Kendall
 
Os examples scheduling
Os examples schedulingOs examples scheduling
Os examples scheduling
 
Multicore system
Multicore systemMulticore system
Multicore system
 
Multimedia
MultimediaMultimedia
Multimedia
 

Recently uploaded

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
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
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
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
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 

Recently uploaded (20)

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
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
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
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
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 

Tree data structure

  • 1. Trees Tree traversal By : Dana Dia’a Data structure and algorithms
  • 2. Tree (ADT)  What is a tree ?  A set of nodes.  Each node can have one or more children .  Each node can have at most one parent. Root ( no parent) Leaves ( no child) Node level 1 2 3 4
  • 3. Binary tree  In binary tree , each node has at most two children .  In other word , it can have zero children ( empty ) , one or two children but not more than two children .  Examples of a binary trees :
  • 4. binary search tree ( BSTree)  Every node entry has a unique key ( keys are not the same in the tree ) .  All the keys in the left of a node are less than the key of a node  All the keys in the right of a node are greater than the key of a node .  Example of a BStree : Left Less than 8 Right Greater than 8
  • 5. A binary tree but NOT binary search tree
  • 6. Search a node  A binary search tree provide an excellent structure for searching a node .  For example : find the node with value 6 .  We compare: 6 is <or > 8( the root) ?  6 is less than 8 so we go to the left of node .  Then we compare : 6 is <or > 3 ?  6 is greater than 3 so we go right to The right of node .  6 is found .
  • 7. Tree traversal  The process of visiting all nodes in a tree only one time .  Two classes :  1 . Breadth – first traversal .  2 . Depth –first traversal .
  • 8. Breadth – first traversal  We can go with two methods : 1. Visiting each node starting from the lowest level ( root ) and moving down level by level , visiting each node from left to right . ( top – down – from left – to right ) . Output : 8 , 3 , 10 ,1 ,6 ,14 ,4 ,7 ,13 Starts
  • 9. Breadth – first traversal (cont.)  The other method is : 1. Visiting each node starting from the highest level ( leaves ) and moving up level by level , visiting each node from right to left . ( bottom – up – from right – to left ) . Starts Output : 13 , 7 ,4 , 14 ,6 ,1 ,10 ,3 ,8
  • 10. Depth – first traversal  We have to consider three tasks in this type .  V – visiting a node .  L – traversing the left sub-tree if any .  R – traversing the right sub-tree if any .  There are six types of depth –first traversal , but we will consider three of them :  VLR ( Preorder )  LVR ( Inorder )  LRV ( Postorder)
  • 11. VLR ( Preorder ) VLR VLR VLR VLRVLR VLR VLR VLR VLR Output : 8 ,3 ,1 ,6 ,4 ,7 ,10 ,14 ,13 Assuming that the visit(v) is to output the value
  • 12. LVR ( Ineorder ) LVR Output : 1 , 3 , 4 , 6 , 7 , 8 ,10 ,13 ,14 Assuming that the visit() is to output the valueLVR LVR LVR LVR LVR LVR LVRLVR
  • 13. LRV ( Posteorder ) LRV Output : 1 , 4 , 7 ,6 ,3 , 13 , 14 , 10 , 8 Assuming that the visit() is to output the value LRV LRV LRV LRV LRV LRVLRVLRV