aula 20 – laboratório: Árvores...
TRANSCRIPT
![Page 1: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/1.jpg)
1
Aula 20 – Laboratório:Árvores AVL
Algoritmos e Estruturas de Dados I
Prof. Jesús P. [email protected]
Q1-2017
![Page 2: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/2.jpg)
2
AVL (Adelson-Velskii e Landis)
![Page 3: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/3.jpg)
3
AVL
G.M. Adelson-Velskii y E.M. Landis“An algorithm for the organization of information”. Proceedings of the USSR Academy of Sciences, vol. 146, pp. 263–266, 1962
AVL foi a primeira estrutura (conhecida) de árvore de altura balanceada/equilibrada.
![Page 4: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/4.jpg)
4
Rotação: Esquerda & Direita
X
YT1
T3T2
Y
T3X
T2T1
Varredura e-r-d: T1, X, T2, Y, T3 Varredura e-r-d: T1, X, T2, Y, T3
R. a direita
R. a esquerda
![Page 5: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/5.jpg)
5
Rotação: LL
p
T3f
T2T1
a
T4 p
f
T2T1
a
T4T3
R. a direita(a)
![Page 6: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/6.jpg)
6
p
T3
Rotação: RR
a
T1
f
T4
p
a
T2T1
f
T4T3
R. a esquerda(a)T2
![Page 7: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/7.jpg)
7
p
T2T1
Rotação: LR
p
fT1
a
T4f
p
T2T1
a
T4T3
R. a esquerda(p)
T3T2
f
a
T4
T3
R. a direita(a)
![Page 8: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/8.jpg)
8
Rotação: RL
T1
f
a
pf
a
T2T1
p
T4T3
R. a direita(p)
T3T2
R. a esquerda(a)
T4
T1
T2
a
f
p
T4T3
![Page 9: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/9.jpg)
9
Atividade prática: AVL
Baixar o arquivo avl.tgz
Descomprimir os arquivos:tar xvfz avl.tgz
O diretório avl contem o código fonte avl.c e 4 arquivos com vetores de teste:
vetor1.dat (20 elementos, ordem crescente)
vetor2.dat (20 elementos, ordem decrescente)
vetor3.dat (20 elementos, aleatório)
vetor4.dat (40000 elementos, aleatório)
Preencher a planilha (aberto até 01/maio, 23h50): https://docs.google.com/spreadsheets/d/1CfWyhAT6UpKHmV-N1p33np5o_E37eLqUpyM5kBLy-_8/edit?usp=sharing
(O bônus, de 0.5 na média das listas, é válido para preenchimento da planilha até 01/maio, 23h50)
![Page 10: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/10.jpg)
10
Atividade prática: AVL
![Page 11: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/11.jpg)
11
Atividade prática: AVL
X
YT1
T3T2
Y
T3X
T2T1
r. a direitar. a esquerda
![Page 12: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/12.jpg)
12
Atividade prática: AVL
![Page 13: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/13.jpg)
13
Atividade prática: AVL
![Page 14: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/14.jpg)
14
Atividade prática: AVL
TO-DO: Você deve implementar essa parte
TO-DO:Você deve implementar essa parte
Veja dicas no código fonteavl.c
![Page 15: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/15.jpg)
15
avl.c
![Page 16: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/16.jpg)
16
Testes empíricos
$ gcc avl.c o avl.exe
$ ./avl.exe < vetor1.dat
$ ./avl.exe < vetor2.dat
$ ./avl.exe < vetor3.dat
$ ./avl.exe < vetor4.dat
Para cada teste serão apresentadas várias informações:
- Veja como o fator de balanceamento está sendo calculado.
- Como os valores são inseridos na ABB?
- Qual é a altura final da árvore? (este valor deverá ser inserido na planilha no GoogleDocs).
- Qual é o número total de rotações que foram realizadas para inserir todos os elementos? (este valor deverá ser inserido na planilha no GoogleDocs).
Para pensar:O teste para o vetor4.dat (com 40mil elementos) tem uma altura inferior a 23?
![Page 17: Aula 20 – Laboratório: Árvores AVLprofessor.ufabc.edu.br/~jesus.mena/courses/mcta001-1q-2017/AED1-20.pdf · AVL G.M. Adelson-Velskii y E.M. Landis “An algorithm for the organization](https://reader031.vdocuments.site/reader031/viewer/2022021700/5c07d1b609d3f29f288bb32c/html5/thumbnails/17.jpg)
17
Comentários finais...
Assista o seguinte vídeo:https://www.youtube.com/watch?v=Pbdo-ozuOug
Use software livre (use Linux!)
Existe uma plataforma, similar ao HackerRank muito utilizada para contratações de estágio em empresas internacionais (Google, Uber, Facebook). Está com um tempinho… faça os testes: https://www.interviewbit.com/problems/loop_cmpl/
Bom recesso!