90 likes | 245 Views
Pertemuan 13 AVL Tree. Matakuliah : T0026/Struktur Data Tahun : 2005 Versi : 1/1. Learning Outcomes. Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mahasiswa dapat menghasilkan program modular untuk mengimplementasikan ADT AVL tree. Outline Materi.
E N D
Pertemuan 13AVL Tree Matakuliah : T0026/Struktur Data Tahun : 2005 Versi : 1/1
Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : • Mahasiswa dapat menghasilkan program modular untuk mengimplementasikan ADT AVL tree
Outline Materi • Pengertian dan penggunaan AVL tree • Contoh AVL Tree • Inerting data AVL tree • Deleting data AVL tree • Contoh program AVL Tree
Introduced by Adelson-Velskii and Landis in 1962 Definition : TL and TR are height balanced |hL - hR|<=1 AVL Tree adalah Binary Search Tree yang mempunyai ketentuan : maksimum perbedaan height antara subtree kiri dan subtree kanan adalah satu Balance Factor, BF(T) : TallLeft : –1 TallRight : +1 Balance : 0 4 kinds of rebalancing : LL : left subtree of the left subtree RR : right subtree of the right subtree LR : right subtree of the left subtree RL : left subtree of the right subtree AVL Tree
INSERT case 1 : BF(T)=0 Operation on AVL Tree Before Insert(80) After Insert(80) +1 0 54 54 +1 0 0 30 70 30 70 0 80 • case 2 : BF(T)=+1 Insert in left subtree for BF(T)=+1. After Insert(10) Before Insert(10) 0 54 +1 54 -1 +1 0 +1 30 70 30 70 0 0 0 10 80 80
Case 3 : Insert in left subtree for BF(T)=-1 Case 4 : Insert in right subtree for BF(T)=+1 Case 5 : Insert in left subtree for BF(T)=+1 Case 6 : Insert in right subtree for BF(T)=-1 Operation on AVL Tree
Single Rotation : LL, RR Operation on AVL Tree +1 +2 54 +1 54 54 0 0 0 +2 0 +1 30 80 30 70 LeftChild 30 70 0 0 +1 0 70 88 Parent 80 80 RightChild 88
Double Rotation Operation on AVL Tree Before Insert(55) Insert(55) -2 -1 60 60 +1 +1 0 +1 20 20 80 80 -1 0 -1 0 0 +1 90 10 90 40 10 40 0 0 +1 0 0 0 5 30 5 50 30 50 55 R1 R2 0 40 60 -1 0 20 60 40 80 -1 0 +1 +1 30 50 80 10 90 20 50 0 0 0 5 55 90 10 30 55 5