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!!!

2-3 Tree, Everything you need to know