SlideShare a Scribd company logo
1 of 117
2-3
TREE
Estrutura de Dados II
Team:
Augusto Teixeira
Carlos Littbarski
Jardel Rodrigues
Victor Apuena
Professor:
Alandson Meireles
History
TREE 2-3 WAS THE FIRST MULTIPATHS TREE, INVENTED BY J. E.
HOPCROFT IN 1970.
2-3 trees are an isometry of AA trees, which means that they are
equivalent data structures. In other words, for all 2-3 tree, there
exists at least one AA tree with data elements in the same order. 2-3
trees are balanced, meaning that each right, center and left subtree
contains the same or close to the same amount of data.
John E. Hopcroft
Characteristics
- ARE TREES EASY TO SCHEDULE
- ARE MULTIVITIES TREES
- IT'S NOT A BINARY TREE
- TREES 2-3 ARE SIMILAR TO TREES 2-3-4.
- 2-3 SAY ABOUT THE QUANTITY OF CHILDREN THAT THE TREE CAN HAVE (AS
WELL AS IN 2-3-4)
- PERFECTLY BALANCED
Advantagens
Perfectly balanced tree
Quick search
Easy implementation
Delayed removal
Disadvantages
Propriedades
- Each node contains one or two keys;
- Each inner node has two children if it has one key, or three if it has two keys;
- All the leaves are on the same level.
- All data is sorted
NODE WITH 1 SON
a a b
P Q
NODE WITH 2 SONS
P Q R
INSETION
Insertion: Empty Tree
Add‘B’
Insertion: Empty Tree
b
If the Tree is empty:
Create a node and add the value to the node
Rule #1
Insert: Node 1-key node
b
Add ‘A’
a
Insert: Node 1-key node
b
Otherwise, locate the node to which the value belongs.
If the node has only 1 value, add the value on the node.
a
Rule #2
Rula #3
Insert key in the node always in an orderly fashion.
Insert: 2-key node
a b
c
Add ‘C’
Insert: 2-key node
c
If the leaf node has more than two values, divide the node
and promote the median of the three values for the parent.
a b
Regra #4
Number of keys burst
Promote the median
Break the knot and make the call
Insert: 2-key node
ca
b
Key > BKey < B
We with 1 key should always have 2 children
Insert: Rules
c
Insert “D”
a
b
Insert: Rules
c
Insert “E”
a
b
d
e
Insert: Rules
ca
b
d e
If the leaf node has more than two values, divide the node
and promote the median of the three values for the parent.Rule #4
Insert: Rules
ca
b d
e
- Each inner node has two children if it has one key, or three if it has two keys;
Insert: Rules: Regras
ca
b d
e Nºs > BNºs < B
keys > B & < D
Let's see if we understand everything?
Empty tree. Enter # 50
Insert #1
50
Insert #25
1 50
Insert #25
1 50
25
Node full!
1 5025
# 25 Promoted | Balanced Tree
1 50
25
Insert #35
1 50
25
Insert #40
1 35
25
50
40
Node full!
1 35
25
5040
#40 Promoted
1
4025
5035
1
4025
5035
Balanced Tree????????
1
4025
5035
No!
#Broken property
1
4025
5035
- Node with 2 keys must
have 3 children
Node (35,50) Split
1
4025
5035
Balanced tree! Enter # 15
1
4025
5035
1 35
25
50
40
Okay! Insert #10
15
10
1 35
25
50
40
Node full!
1510
1 35
25
50
40
Limit burst! AGAIN!!!
15
10
25 4010
If the parent then has
three values, continue
to divide and promote,
forming a new root
node if necessary
Rule #5
1 35 5015
Limit burst! AGAIN!!!
25
40
Mama's lovely thing !!!
10
1 35 5015
Enough right? Let's go to the next!
1 35
25
50
40
15
10
SEARCH
2-3 Tree
▪ Simple Node:
▪ Contains a key and two links; A left link to a 2-3 tree that
has keys smaller than the node key; And a direct link to a 2-
3 tree that has larger braces;
2-3 Tree
▪ Double Node:
▪ Contains two keys and three links: a left link to a 2-3 tree
that has smaller keys; And a middle link to a 2-3 tree that has
keys between the two keys of the node; And a direct link to a
2-3 tree that has larger braces;
Search in a tree 2-3
- It always starts at the root;
- If the searched item is not in the root, it identifies the child
node of the root in which it can be and continues to this node;
- If the item has a value greater than the root, go to the right of
the tree, otherwise go to the left;
- The process repeats itself until the item is found;
Search example Tree 2-3
3
30
29
5010 20
12 18 40 43 7060
Searching the 18
3
30
29
50
12 18
10 20
40 43 7060
Search example Tree 2-3
Searching the 18
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 18
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 18
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 18
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 18
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 18
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 18
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 18
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 65
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 65
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 65
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 65
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 65
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 65
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 65
3
30
29
5010 20
12 18 40 43 7060
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 43
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 43
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 43
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 43
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 43
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 43
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 43
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 43
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 3
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 3
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 3
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 3
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 3
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 3
3
30
29
5010 20
12 18 40 43 7060
Search example Tree 2-3
Searching the 3
REMOVAL
Removing a tree 2-3
- Removing an item from a tree 2-3 is approximately the reverse of the insertion
process;
- To remove an item, we must first look for it;
- If the item to be removed is on a sheet with two items;
- We simply exclude it;
- We remove it by changing it from the trees;
Removing #45
- Find #45
1 35
25
60
10
6545
40 50
15
Removing #45
1 35
25
60
10
6545
40 50
15
Removing #45
1 35
25
6015
10
6550
40 50
Removing #45
1 35
25
6015
10
6550
40 60
Removing #45
1 35
25
15
10
6550
40 60
Removing #45
- procurar número 40
1 35
25
15
10
6550
40 60
Removing #45
1 35
25
15
10
6550
40 60
Removing #45
1 35
25
15
10
6550
35 60
Removing #45
1
25
15
10
6550
35 60
After removing #45
1
25
15
10
6535
60
50
Removing #1
- Find #1
1
25
15
10
6535
60
50
1
25
15
10
6535
60
50
Removing #1
25
15
10
6535
60
50
Removing #1
25
10
6535
60
50
15
Removing #1
25
10
6535
60
50
15
Removing #1
25
10 6535
60
5015
Removing #1
- Find #10
25
10 6535
60
5015
Removing #10
25
10 6535
60
5015
Removing #10
25
6535
60
5015
After Remove #10
25
6535
60
5015
Removing #35
25
6535
60
5015
Removing #35
25
65
60
5015
Removing #35
25
65
60
5015
Removing #60
25
65
60
5015
Removing #60
25
65
65
5015
Removing #60
25 65
5015
Removing #60
25
655015
Removing #60
25
655015
Removing #60
25
655015
Removing #60
25
5015
Removing #60
25
5015
Removing #50
25
5015
Removing #50
25
15
Removing #50
2515
After Remove #50
2515
Removing #25
15
Removing #15
Empty Tree
REFERÊNCIAS
USP - “Instituto de Matemática e Estatística”. Disponível em:
https://www.ime.usp.br/~gold/cursos/2002/mac2301/aulas/b-arvore/
LAFORE - ESTRUTURA DE DADOS E ALGORÍTMOS EM JAVA - 2ª EDIÇÃO
WIKIPEDIA - https://pt.wikipedia.org/wiki/%C3%81rvore_2-3
Gross, R. Hernández, J. C. Lázaro, R. Dormido, S. Ros (2001). Estructura de Datos
y Algoritmos Prentice Hall
Ellio B. Koffman Paul A. T. Olfgang (2006) : Objetos, Abstração, Estruturas de
dados e projeto usando C++
Thank you
very much!!!

More Related Content

Similar to 2-3 Tree, Everything you need to know

Similar to 2-3 Tree, Everything you need to know (13)

B trees2
B trees2B trees2
B trees2
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 
16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structure16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
B trees
B treesB trees
B trees
 
B+ tree
B+ treeB+ tree
B+ tree
 
BTrees-fall2010.ppt
BTrees-fall2010.pptBTrees-fall2010.ppt
BTrees-fall2010.ppt
 
08 B Trees
08 B Trees08 B Trees
08 B Trees
 
B trees
B treesB trees
B trees
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
4a searching-more
4a searching-more4a searching-more
4a searching-more
 
B tree
B treeB tree
B tree
 

Recently uploaded

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

2-3 Tree, Everything you need to know