SlideShare une entreprise Scribd logo
1  sur  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!!!

Contenu connexe

Similaire à 2-3 Tree, Everything you need to know

Similaire à 2-3 Tree, Everything you need to know (14)

2-3 Tree
2-3 Tree2-3 Tree
2-3 Tree
 
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
 

Dernier

How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideStefan Dietze
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireExakis Nelite
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Hiroshi SHIBATA
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Patrick Viafore
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfUK Journal
 

Dernier (20)

How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 

2-3 Tree, Everything you need to know