Ávores avl
DESCRIPTION
Ávores AVL. MC 202 – Estruturas de dados. Cristiano Damaschio Ferreira [email protected]. Introdução. Árvore binária de busca. Introdução. Árvore binária de busca. h = 2. É AVL. h = 1. h = 0. h = 0. h = 0. AVL. |H R – H L | < 2 Exemplos:. h = 2. NÃO É AVL. h = 1. h = 0. - PowerPoint PPT PresentationTRANSCRIPT
![Page 2: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/2.jpg)
Introdução
Árvore binária de busca
![Page 3: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/3.jpg)
Introdução
Árvore binária de busca
![Page 4: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/4.jpg)
AVL
|HR – HL| < 2 Exemplos: h = 2
h = 1 h = 0
h = 0 h = 0
É AVL
![Page 5: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/5.jpg)
AVL
|HR – HL| < 2 Exemplos: h = 2
h = 1
h = 0 h = 0
NÃO É AVL
![Page 6: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/6.jpg)
AVL
Fator de balanceamento b = HR – HL
Exemplo: b = 0
b = 0 b = +1
b = 0 b = 0 b = 0
![Page 7: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/7.jpg)
AVL
Inserção Semelhante à inserção em árvore
binária de busca
Pode desbalancear a árvore
![Page 8: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/8.jpg)
AVL
Exemplo Inserção do valor 5
b = 0
b = -1 b = +1
b = 0 b = 0
b = 0
b = -2
b = -1
b = 0
b = +1
b = 0
![Page 9: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/9.jpg)
AVL
Caso a
![Page 10: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/10.jpg)
AVL
Caso b
![Page 11: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/11.jpg)
AVL
Caso c
![Page 12: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/12.jpg)
AVL
Caso d
![Page 13: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/13.jpg)
AVL
Remanejamento das árvores Rotação simples à direita
Rotação dupla à direita
Rotação simples à esquerda
Rotação dupla à esquerda
![Page 14: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/14.jpg)
AVL
Rotação simples à direita
![Page 15: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/15.jpg)
AVL
Rotação simples à direita ne é colocado na raiz EE permanece a sub-árvore esquerda de
ne
n torna-se a raiz da sub-árvore direita de ne
ED torna-se sub-árvore esquerda de n D permanece a sub-árvore direita de n
![Page 16: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/16.jpg)
AVL
Rotação dupla à direita
![Page 17: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/17.jpg)
AVL
O caso c é similar ao caso a
![Page 18: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/18.jpg)
AVL
O caso d é similar ao caso b
![Page 19: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/19.jpg)
AVL
A remoção é similar à remoção em árvore binária de busca Primeiro, busca-se o nó que contém o
valor a ser removido. Se o nó for folha, remove-o Se o nó possuir um filho, esse filho
substitui o nó Senão, busca-se a menor (maior) folha
da sub-árvore direita (esquerda) do nó, substitui o nó por essa folha
![Page 20: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/20.jpg)
AVL
A remoção pode desbalancear a árvore Exemplo 1: remover 25
![Page 21: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/21.jpg)
AVL
Exemplo 1
![Page 22: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/22.jpg)
AVL
Exemplo 1
![Page 23: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/23.jpg)
AVL
Exemplo 2: Retirar 70
![Page 24: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/24.jpg)
AVL
Exemplo 2:
![Page 25: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/25.jpg)
AVL
Exemplo 2:
![Page 26: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/26.jpg)
AVL
Exemplo 3: Retirar 50
![Page 27: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/27.jpg)
AVL
Exemplo 3:
![Page 28: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/28.jpg)
AVL
Exemplo 3:
![Page 29: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/29.jpg)
AVL
Exemplo 3:
![Page 30: Ávores AVL](https://reader031.vdocuments.mx/reader031/viewer/2022031805/5681344e550346895d9b34d3/html5/thumbnails/30.jpg)
AVL
Exemplo 3: