SlideShare a Scribd company logo
Lecture # 10Lecture # 10
Operations on Binary TreeOperations on Binary Tree
 There are a number of operations that canThere are a number of operations that can
be defined for a binary tree.be defined for a binary tree.
 IfIf pp is pointing to a node in an existing tree thenis pointing to a node in an existing tree then
 left(left(pp)) returns pointer to the left subtreereturns pointer to the left subtree
 right(right(pp)) returns pointer to right subtreereturns pointer to right subtree
 parent(parent(pp)) returns the father ofreturns the father of pp
 brother(brother(pp)) returns brother ofreturns brother of pp..
 info(p)info(p) returns content of the node.returns content of the node.
Operations on Binary TreeOperations on Binary Tree
 In order to construct a binary tree, theIn order to construct a binary tree, the
following can be useful:following can be useful:
 setLeft(p,x)setLeft(p,x) creates the left child node of p.creates the left child node of p.
The child node contains the info ‘x’.The child node contains the info ‘x’.
 setRight(p,x)setRight(p,x) creates the right child node ofcreates the right child node of
p. The child node contains the info ‘x’.p. The child node contains the info ‘x’.
Applications of Binary TreesApplications of Binary Trees
 A binary tree is a useful data structure when two-A binary tree is a useful data structure when two-
way decisions must be made at each point in away decisions must be made at each point in a
process.process.
 For example, suppose we wanted to find allFor example, suppose we wanted to find all
duplicates in a list of numbers:duplicates in a list of numbers:
14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 514, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
Applications of Binary TreesApplications of Binary Trees
 One way of finding duplicates is to compareOne way of finding duplicates is to compare
each number with all those thateach number with all those that precedeprecede it.it.
14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 514, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 514, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
Searching for DuplicatesSearching for Duplicates
 If the list of numbers is large and is growing, thisIf the list of numbers is large and is growing, this
procedure involves a large number ofprocedure involves a large number of
comparisons.comparisons.
 A linked list could handle the growth but theA linked list could handle the growth but the
comparisons would still be large.comparisons would still be large.
 The number of comparisons can be drasticallyThe number of comparisons can be drastically
reduced by using a binary tree.reduced by using a binary tree.
 The tree grows dynamically like the linked list.The tree grows dynamically like the linked list.
Searching for DuplicatesSearching for Duplicates
 The binary tree is built in a special way.The binary tree is built in a special way.
 The first number in the list is placed in a nodeThe first number in the list is placed in a node
that is designated as the root of a binary tree.that is designated as the root of a binary tree.
 Initially, both left and right subtrees of the root areInitially, both left and right subtrees of the root are
empty.empty.
 We take the next number and compare it with theWe take the next number and compare it with the
number placed in the root.number placed in the root.
 If it is the same then we have a duplicate.If it is the same then we have a duplicate.
Searching for DuplicatesSearching for Duplicates
 Otherwise, we create a new tree node and put theOtherwise, we create a new tree node and put the
new number in it.new number in it.
 The new node is made the left child of the rootThe new node is made the left child of the root
node if the second number is less than the one innode if the second number is less than the one in
the root.the root.
 The new node is made the right child if theThe new node is made the right child if the
number is greater than the one in the root.number is greater than the one in the root.
Searching for DuplicatesSearching for Duplicates
Searching for DuplicatesSearching for Duplicates
Searching for DuplicatesSearching for Duplicates
Searching for DuplicatesSearching for Duplicates
Searching for DuplicatesSearching for Duplicates
Searching for DuplicatesSearching for Duplicates
Searching for DuplicatesSearching for Duplicates
Searching for DuplicatesSearching for Duplicates
Searching for DuplicatesSearching for Duplicates
 DuplicateDuplicate (4)(4) Appeared …..Appeared …..
 DuplicateDuplicate (9),(9), (14),(14), (5),(5), Appeared …..Appeared …..
Tree TraversalsTree Traversals
1.1. PreOrderPreOrder
2.2. InOrderInOrder
3.3. PostOrderPostOrder
PreorderPreorder
 To traverse non empty binary tree inTo traverse non empty binary tree in
PreorderPreorder,, we perform the followingwe perform the following
operations.operations.
1.1. Visit theVisit the RootRoot
2.2. Traverse theTraverse the leftleft sub tree insub tree in preorderpreorder
3.3. Traverse theTraverse the rightright sub tree insub tree in preorderpreorder
InorderInorder
 To traverse a non empty binary tree inTo traverse a non empty binary tree in
Inorder (or Symmetric Order)Inorder (or Symmetric Order),, wewe
perform the following operations.perform the following operations.
1.1. Traverse theTraverse the leftleft sub tree insub tree in InorderInorder
2.2. Visit theVisit the RootRoot
3.3. Traverse theTraverse the rightright sub tree insub tree in InorderInorder
PostorderPostorder
 To traverse non empty binary tree inTo traverse non empty binary tree in
PostorderPostorder,, we perform the followingwe perform the following
operations.operations.
1.1. Traverse theTraverse the leftleft sub tree insub tree in postorderpostorder
2.2. Traverse theTraverse the rightright sub tree insub tree in postorderpostorder
3.3. Visit theVisit the RootRoot
Example of Tree TraversalsExample of Tree Traversals
AA
CC
EE
HH
FF GG
DD
II
BB
JJ
LLKK
 PreOrder : A B C E I F J D G H K LPreOrder : A B C E I F J D G H K L
 InOrder : E I C F J B G D K H L AInOrder : E I C F J B G D K H L A
 PostOrder : I E J F C G K L H D B APostOrder : I E J F C G K L H D B A

More Related Content

What's hot

BinarySearchTree-bddicken
BinarySearchTree-bddickenBinarySearchTree-bddicken
BinarySearchTree-bddicken
Benjamin Dicken
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
Dwight Sabio
 
Phylogenetics in R
Phylogenetics in RPhylogenetics in R
Phylogenetics in R
schamber
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Krish_ver2
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Zafar Ayub
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating stringsNicole Ryan
 
binary search tree
binary search treebinary search tree
binary search tree
Shankar Bishnoi
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Convert column-number-to-letter
Convert column-number-to-letterConvert column-number-to-letter
Convert column-number-to-letter
Partha Pratim Chakraborty
 
10 Red-Black Trees
10 Red-Black Trees10 Red-Black Trees
10 Red-Black Trees
Andres Mendez-Vazquez
 
4a searching-more
4a searching-more4a searching-more
4a searching-moreShahzad Ali
 
Mathematics: Addition Then Subtraction
Mathematics: Addition Then  Subtraction Mathematics: Addition Then  Subtraction
Mathematics: Addition Then Subtraction
LorenKnights
 
Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
IJERD Editor
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
PyOhio Recursion Slides
PyOhio Recursion SlidesPyOhio Recursion Slides
PyOhio Recursion Slides
Rinita Gulliani
 
Binary Search Tree (BST)
Binary Search Tree (BST)Binary Search Tree (BST)
Binary Search Tree (BST)
M Sajid R
 
Trees
TreesTrees

What's hot (17)

BinarySearchTree-bddicken
BinarySearchTree-bddickenBinarySearchTree-bddicken
BinarySearchTree-bddicken
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Phylogenetics in R
Phylogenetics in RPhylogenetics in R
Phylogenetics in R
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
 
binary search tree
binary search treebinary search tree
binary search tree
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Convert column-number-to-letter
Convert column-number-to-letterConvert column-number-to-letter
Convert column-number-to-letter
 
10 Red-Black Trees
10 Red-Black Trees10 Red-Black Trees
10 Red-Black Trees
 
4a searching-more
4a searching-more4a searching-more
4a searching-more
 
Mathematics: Addition Then Subtraction
Mathematics: Addition Then  Subtraction Mathematics: Addition Then  Subtraction
Mathematics: Addition Then Subtraction
 
Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
PyOhio Recursion Slides
PyOhio Recursion SlidesPyOhio Recursion Slides
PyOhio Recursion Slides
 
Binary Search Tree (BST)
Binary Search Tree (BST)Binary Search Tree (BST)
Binary Search Tree (BST)
 
Trees
TreesTrees
Trees
 

Viewers also liked

Web 2 y web 3
Web 2 y web 3 Web 2 y web 3
Links
LinksLinks
Bullion Trading Tips & News
Bullion Trading Tips & NewsBullion Trading Tips & News
Bullion Trading Tips & News
Nisha Sharma
 
Analysis of ‘Rocky Balboa’
Analysis of ‘Rocky Balboa’Analysis of ‘Rocky Balboa’
Analysis of ‘Rocky Balboa’
holladolla
 
Person centred care Poll 15
Person centred care Poll 15Person centred care Poll 15
Person centred care Poll 15
NHS Improving Quality
 
Web 2 y web 3 1
Web 2 y web 3 1Web 2 y web 3 1
How to Deal in Currency Market
How to Deal in Currency MarketHow to Deal in Currency Market
How to Deal in Currency Market
Nisha Sharma
 
My quotes
My quotesMy quotes
Dd
DdDd
Designing Digital Forms
Designing Digital FormsDesigning Digital Forms
Designing Digital Forms
Netcetera
 
Academic_Progress_Letter_823707666_20140326_2122
Academic_Progress_Letter_823707666_20140326_2122Academic_Progress_Letter_823707666_20140326_2122
Academic_Progress_Letter_823707666_20140326_2122Alexander Smith
 
La religion à new york
La  religion à new yorkLa  religion à new york
La religion à new york
Coraline Luquet
 
Présentation Computraining
Présentation ComputrainingPrésentation Computraining
Présentation Computraining
Guillaume Blnchn
 
States, boiling point,_melting_point,
States, boiling point,_melting_point,States, boiling point,_melting_point,
States, boiling point,_melting_point,Durant Road Middle
 
Síndrome hipotónico del lactante
Síndrome hipotónico del lactanteSíndrome hipotónico del lactante
Síndrome hipotónico del lactante
Frank Pineda
 

Viewers also liked (16)

Web 2 y web 3
Web 2 y web 3 Web 2 y web 3
Web 2 y web 3
 
Links
LinksLinks
Links
 
Bullion Trading Tips & News
Bullion Trading Tips & NewsBullion Trading Tips & News
Bullion Trading Tips & News
 
Analysis of ‘Rocky Balboa’
Analysis of ‘Rocky Balboa’Analysis of ‘Rocky Balboa’
Analysis of ‘Rocky Balboa’
 
Person centred care Poll 15
Person centred care Poll 15Person centred care Poll 15
Person centred care Poll 15
 
ExperienceTRP
ExperienceTRPExperienceTRP
ExperienceTRP
 
Web 2 y web 3 1
Web 2 y web 3 1Web 2 y web 3 1
Web 2 y web 3 1
 
How to Deal in Currency Market
How to Deal in Currency MarketHow to Deal in Currency Market
How to Deal in Currency Market
 
My quotes
My quotesMy quotes
My quotes
 
Dd
DdDd
Dd
 
Designing Digital Forms
Designing Digital FormsDesigning Digital Forms
Designing Digital Forms
 
Academic_Progress_Letter_823707666_20140326_2122
Academic_Progress_Letter_823707666_20140326_2122Academic_Progress_Letter_823707666_20140326_2122
Academic_Progress_Letter_823707666_20140326_2122
 
La religion à new york
La  religion à new yorkLa  religion à new york
La religion à new york
 
Présentation Computraining
Présentation ComputrainingPrésentation Computraining
Présentation Computraining
 
States, boiling point,_melting_point,
States, boiling point,_melting_point,States, boiling point,_melting_point,
States, boiling point,_melting_point,
 
Síndrome hipotónico del lactante
Síndrome hipotónico del lactanteSíndrome hipotónico del lactante
Síndrome hipotónico del lactante
 

Similar to Lecture10

6_1 (1).ppt
6_1 (1).ppt6_1 (1).ppt
6_1 (1).ppt
ayeshamangrio3
 
computer notes - Binary tree
computer notes - Binary treecomputer notes - Binary tree
computer notes - Binary tree
ecomputernotes
 
computer notes - Binary search tree
computer notes - Binary search treecomputer notes - Binary search tree
computer notes - Binary search tree
ecomputernotes
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)
amna izzat
 
Data Structures
Data StructuresData Structures
Data Structures
Nitesh Bichwani
 
Data structures final lecture 1
Data structures final  lecture 1Data structures final  lecture 1
Data structures final lecture 1
Nazir Ahmed
 
Lecture_10 - Revised.pptx
Lecture_10 - Revised.pptxLecture_10 - Revised.pptx
Lecture_10 - Revised.pptx
RedHeart11
 
e computer notes - Binary search tree
e computer notes - Binary search treee computer notes - Binary search tree
e computer notes - Binary search treeecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13ecomputernotes
 
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
Data Structures and Agorithm: DS 10 Binary Search Tree.pptxData Structures and Agorithm: DS 10 Binary Search Tree.pptx
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
RashidFaridChishti
 
Extend your work on the OCC logo to add shapes that curve1 the blue.pdf
Extend your work on the OCC logo to add shapes that curve1 the blue.pdfExtend your work on the OCC logo to add shapes that curve1 the blue.pdf
Extend your work on the OCC logo to add shapes that curve1 the blue.pdf
arihantcommunication
 
L 17 ct1120
L 17 ct1120L 17 ct1120
L 17 ct1120
Zia Ush Shamszaman
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
Muhazzab Chouhadry
 
LEC 5-DS ALGO(updated).pdf
LEC 5-DS  ALGO(updated).pdfLEC 5-DS  ALGO(updated).pdf
LEC 5-DS ALGO(updated).pdf
MuhammadUmerIhtisham
 
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
 
Balanced binary search tree on array
Balanced binary search tree on array Balanced binary search tree on array
Balanced binary search tree on array Pier Giuliano Nioi
 
Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms
CourseHunt
 
computer notes - Data Structures - 12
computer notes - Data Structures - 12computer notes - Data Structures - 12
computer notes - Data Structures - 12ecomputernotes
 

Similar to Lecture10 (20)

6_1 (1).ppt
6_1 (1).ppt6_1 (1).ppt
6_1 (1).ppt
 
Binary trees
Binary treesBinary trees
Binary trees
 
computer notes - Binary tree
computer notes - Binary treecomputer notes - Binary tree
computer notes - Binary tree
 
computer notes - Binary search tree
computer notes - Binary search treecomputer notes - Binary search tree
computer notes - Binary search tree
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)
 
Data Structures
Data StructuresData Structures
Data Structures
 
Data structures final lecture 1
Data structures final  lecture 1Data structures final  lecture 1
Data structures final lecture 1
 
Lecture_10 - Revised.pptx
Lecture_10 - Revised.pptxLecture_10 - Revised.pptx
Lecture_10 - Revised.pptx
 
e computer notes - Binary search tree
e computer notes - Binary search treee computer notes - Binary search tree
e computer notes - Binary search tree
 
Unit8 C
Unit8 CUnit8 C
Unit8 C
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
Data Structures and Agorithm: DS 10 Binary Search Tree.pptxData Structures and Agorithm: DS 10 Binary Search Tree.pptx
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
 
Extend your work on the OCC logo to add shapes that curve1 the blue.pdf
Extend your work on the OCC logo to add shapes that curve1 the blue.pdfExtend your work on the OCC logo to add shapes that curve1 the blue.pdf
Extend your work on the OCC logo to add shapes that curve1 the blue.pdf
 
L 17 ct1120
L 17 ct1120L 17 ct1120
L 17 ct1120
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
LEC 5-DS ALGO(updated).pdf
LEC 5-DS  ALGO(updated).pdfLEC 5-DS  ALGO(updated).pdf
LEC 5-DS ALGO(updated).pdf
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 
Balanced binary search tree on array
Balanced binary search tree on array Balanced binary search tree on array
Balanced binary search tree on array
 
Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms
 
computer notes - Data Structures - 12
computer notes - Data Structures - 12computer notes - Data Structures - 12
computer notes - Data Structures - 12
 

More from Muhammad Zubair

Cloud computing
Cloud computingCloud computing
Cloud computing
Muhammad Zubair
 
Cloud computing disadvantages
Cloud computing disadvantagesCloud computing disadvantages
Cloud computing disadvantages
Muhammad Zubair
 
Lecture8
Lecture8Lecture8
Lecture8
Muhammad Zubair
 
Lecture7
Lecture7Lecture7
Lecture7
Muhammad Zubair
 
Lecture6
Lecture6Lecture6
Lecture6
Muhammad Zubair
 
Lecture5
Lecture5Lecture5
Lecture5
Muhammad Zubair
 
Lecture4
Lecture4Lecture4
Lecture4
Muhammad Zubair
 
Lecture3
Lecture3Lecture3
Lecture3
Muhammad Zubair
 
Lecture3
Lecture3Lecture3
Lecture3
Muhammad Zubair
 
Lecture2
Lecture2Lecture2
Lecture2
Muhammad Zubair
 
Lecture1
Lecture1Lecture1
Lecture1
Muhammad Zubair
 
Indin report by zubair
Indin report by zubairIndin report by zubair
Indin report by zubair
Muhammad Zubair
 
Cyber crime in pakistan by zubair
Cyber crime in pakistan by zubairCyber crime in pakistan by zubair
Cyber crime in pakistan by zubair
Muhammad Zubair
 

More from Muhammad Zubair (13)

Cloud computing
Cloud computingCloud computing
Cloud computing
 
Cloud computing disadvantages
Cloud computing disadvantagesCloud computing disadvantages
Cloud computing disadvantages
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture7
Lecture7Lecture7
Lecture7
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture5
Lecture5Lecture5
Lecture5
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture2
Lecture2Lecture2
Lecture2
 
Lecture1
Lecture1Lecture1
Lecture1
 
Indin report by zubair
Indin report by zubairIndin report by zubair
Indin report by zubair
 
Cyber crime in pakistan by zubair
Cyber crime in pakistan by zubairCyber crime in pakistan by zubair
Cyber crime in pakistan by zubair
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
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
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
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
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
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
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
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
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).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...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.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
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
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
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 

Lecture10

  • 2. Operations on Binary TreeOperations on Binary Tree  There are a number of operations that canThere are a number of operations that can be defined for a binary tree.be defined for a binary tree.  IfIf pp is pointing to a node in an existing tree thenis pointing to a node in an existing tree then  left(left(pp)) returns pointer to the left subtreereturns pointer to the left subtree  right(right(pp)) returns pointer to right subtreereturns pointer to right subtree  parent(parent(pp)) returns the father ofreturns the father of pp  brother(brother(pp)) returns brother ofreturns brother of pp..  info(p)info(p) returns content of the node.returns content of the node.
  • 3. Operations on Binary TreeOperations on Binary Tree  In order to construct a binary tree, theIn order to construct a binary tree, the following can be useful:following can be useful:  setLeft(p,x)setLeft(p,x) creates the left child node of p.creates the left child node of p. The child node contains the info ‘x’.The child node contains the info ‘x’.  setRight(p,x)setRight(p,x) creates the right child node ofcreates the right child node of p. The child node contains the info ‘x’.p. The child node contains the info ‘x’.
  • 4. Applications of Binary TreesApplications of Binary Trees  A binary tree is a useful data structure when two-A binary tree is a useful data structure when two- way decisions must be made at each point in away decisions must be made at each point in a process.process.  For example, suppose we wanted to find allFor example, suppose we wanted to find all duplicates in a list of numbers:duplicates in a list of numbers: 14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 514, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
  • 5. Applications of Binary TreesApplications of Binary Trees  One way of finding duplicates is to compareOne way of finding duplicates is to compare each number with all those thateach number with all those that precedeprecede it.it. 14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 514, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5 14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 514, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
  • 6. Searching for DuplicatesSearching for Duplicates  If the list of numbers is large and is growing, thisIf the list of numbers is large and is growing, this procedure involves a large number ofprocedure involves a large number of comparisons.comparisons.  A linked list could handle the growth but theA linked list could handle the growth but the comparisons would still be large.comparisons would still be large.  The number of comparisons can be drasticallyThe number of comparisons can be drastically reduced by using a binary tree.reduced by using a binary tree.  The tree grows dynamically like the linked list.The tree grows dynamically like the linked list.
  • 7. Searching for DuplicatesSearching for Duplicates  The binary tree is built in a special way.The binary tree is built in a special way.  The first number in the list is placed in a nodeThe first number in the list is placed in a node that is designated as the root of a binary tree.that is designated as the root of a binary tree.  Initially, both left and right subtrees of the root areInitially, both left and right subtrees of the root are empty.empty.  We take the next number and compare it with theWe take the next number and compare it with the number placed in the root.number placed in the root.  If it is the same then we have a duplicate.If it is the same then we have a duplicate.
  • 8. Searching for DuplicatesSearching for Duplicates  Otherwise, we create a new tree node and put theOtherwise, we create a new tree node and put the new number in it.new number in it.  The new node is made the left child of the rootThe new node is made the left child of the root node if the second number is less than the one innode if the second number is less than the one in the root.the root.  The new node is made the right child if theThe new node is made the right child if the number is greater than the one in the root.number is greater than the one in the root.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.  DuplicateDuplicate (4)(4) Appeared …..Appeared …..
  • 23.
  • 24.
  • 25.
  • 26.  DuplicateDuplicate (9),(9), (14),(14), (5),(5), Appeared …..Appeared …..
  • 27. Tree TraversalsTree Traversals 1.1. PreOrderPreOrder 2.2. InOrderInOrder 3.3. PostOrderPostOrder
  • 28. PreorderPreorder  To traverse non empty binary tree inTo traverse non empty binary tree in PreorderPreorder,, we perform the followingwe perform the following operations.operations. 1.1. Visit theVisit the RootRoot 2.2. Traverse theTraverse the leftleft sub tree insub tree in preorderpreorder 3.3. Traverse theTraverse the rightright sub tree insub tree in preorderpreorder
  • 29. InorderInorder  To traverse a non empty binary tree inTo traverse a non empty binary tree in Inorder (or Symmetric Order)Inorder (or Symmetric Order),, wewe perform the following operations.perform the following operations. 1.1. Traverse theTraverse the leftleft sub tree insub tree in InorderInorder 2.2. Visit theVisit the RootRoot 3.3. Traverse theTraverse the rightright sub tree insub tree in InorderInorder
  • 30. PostorderPostorder  To traverse non empty binary tree inTo traverse non empty binary tree in PostorderPostorder,, we perform the followingwe perform the following operations.operations. 1.1. Traverse theTraverse the leftleft sub tree insub tree in postorderpostorder 2.2. Traverse theTraverse the rightright sub tree insub tree in postorderpostorder 3.3. Visit theVisit the RootRoot
  • 31. Example of Tree TraversalsExample of Tree Traversals AA CC EE HH FF GG DD II BB JJ LLKK  PreOrder : A B C E I F J D G H K LPreOrder : A B C E I F J D G H K L  InOrder : E I C F J B G D K H L AInOrder : E I C F J B G D K H L A  PostOrder : I E J F C G K L H D B APostOrder : I E J F C G K L H D B A