SlideShare a Scribd company logo
1 of 14
RITAMBHARA
2-3 TREE-INSERTION
2-3 Trees were developped by John hopcraft in 1974.
To keep the height of a binary search tree low, 2-3 trees were
developped.
A2-3 tree is a binary search tree that can have the following
nodes.
i) Leaf node
ii) 2-node
iii) 3-node
A 2-node contains a single data element (or) key element and it
has two children. X
L R
A 3- node contains two ordered Key elements (or) Data
Element and it has 3 children.
X | Y
L M R
3 -node
Two key elements are ordered i.e., x<y
Example of 2-3 tree:
40
25 65 | 85
20 35 55 70 95 | 102
Leaf nodes does not have child and one or two
data elements (or) key elements.
PROPERTIES
 Every internal node is a 2-node or a 3-node.
 Data or key elements are stored in sorted
order.
 Each node has either one data value or two
data values.
 Leaf nodes have no children and one or two
data elements or key elements.
Operation performed on 2-3 tree are:
i) Insert
ii) Delete
iii) Search
All the operations completed in o(logn)
time.
The time completely of 2-3 tree is o(log2n).
EXAMPLE
 45,67,88,34,12,77,23,55
 take 45 as root node
 Insert 67
67 is greater than 45, so it go right of 45
45
45 | 67
Insert 88
88 is greater than 67, so it go right of 67
45 | 67 | 88
Now, it is invalid tree
It break from middle…
67
45 88
Now insert 34
34 is lesser than 45, so 34 go left of 45..
67
34 | 45 88
Insert 12…
12 is lesser than 34, so it go to left of
34..
67
12 | 34 | 45 88
Now, it is invalid
tree
34 | 67
12 45 88
Insert 77
77 is lesser than 88, so 77 go to left of 88
34 | 67
12 45 77 | 88
Insert 23
23 is lesser than 12, so 23 is right of 12
34 | 67
12 | 23 45 77 | 88
Insert 55
55 is greater than 45, so 55 is right of 45
34 | 67
12 | 23 45 |55 77 | 88
2 3 tree

More Related Content

What's hot (7)

RADIX SORT
RADIX SORT RADIX SORT
RADIX SORT
 
Matrix basic operations
Matrix basic operationsMatrix basic operations
Matrix basic operations
 
Linear algebra for deep learning
Linear algebra for deep learningLinear algebra for deep learning
Linear algebra for deep learning
 
b+ tree
b+ treeb+ tree
b+ tree
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Lecture 1 an introduction to data structure
Lecture 1   an introduction to data structureLecture 1   an introduction to data structure
Lecture 1 an introduction to data structure
 
Basic Electric Circuits Tutorial 4
Basic Electric Circuits Tutorial 4Basic Electric Circuits Tutorial 4
Basic Electric Circuits Tutorial 4
 

Recently uploaded

Recently uploaded (20)

[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
 
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 

2 3 tree

  • 2. 2-3 Trees were developped by John hopcraft in 1974. To keep the height of a binary search tree low, 2-3 trees were developped. A2-3 tree is a binary search tree that can have the following nodes. i) Leaf node ii) 2-node iii) 3-node A 2-node contains a single data element (or) key element and it has two children. X L R
  • 3. A 3- node contains two ordered Key elements (or) Data Element and it has 3 children. X | Y L M R 3 -node Two key elements are ordered i.e., x<y
  • 4. Example of 2-3 tree: 40 25 65 | 85 20 35 55 70 95 | 102 Leaf nodes does not have child and one or two data elements (or) key elements.
  • 5. PROPERTIES  Every internal node is a 2-node or a 3-node.  Data or key elements are stored in sorted order.  Each node has either one data value or two data values.  Leaf nodes have no children and one or two data elements or key elements.
  • 6. Operation performed on 2-3 tree are: i) Insert ii) Delete iii) Search All the operations completed in o(logn) time. The time completely of 2-3 tree is o(log2n).
  • 7. EXAMPLE  45,67,88,34,12,77,23,55  take 45 as root node  Insert 67 67 is greater than 45, so it go right of 45 45 45 | 67
  • 8. Insert 88 88 is greater than 67, so it go right of 67 45 | 67 | 88 Now, it is invalid tree It break from middle… 67 45 88
  • 9. Now insert 34 34 is lesser than 45, so 34 go left of 45.. 67 34 | 45 88 Insert 12…
  • 10. 12 is lesser than 34, so it go to left of 34.. 67 12 | 34 | 45 88 Now, it is invalid tree
  • 11. 34 | 67 12 45 88 Insert 77 77 is lesser than 88, so 77 go to left of 88 34 | 67 12 45 77 | 88
  • 12. Insert 23 23 is lesser than 12, so 23 is right of 12 34 | 67 12 | 23 45 77 | 88 Insert 55 55 is greater than 45, so 55 is right of 45
  • 13. 34 | 67 12 | 23 45 |55 77 | 88