Matakuliah Tahun Versi : T0026/Struktur Data : 2005 : 1/1 Pertemuan 13 AVL Tree 1 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : • Mahasiswa dapat menghasilkan program modular untuk mengimplementasikan ADT AVL tree 2 Outline Materi • • • • • Pengertian dan penggunaan AVL tree Contoh AVL Tree Inerting data AVL tree Deleting data AVL tree Contoh program AVL Tree 3 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 4 Operation on AVL Tree • INSERT – case 1 : BF(T)=0 0 54 54 0 +1 0 30 30 70 70 0 80 Before Insert(80) – +1 After Insert(80) case 2 : BF(T)=+1 Insert in left subtree for BF(T)=+1. 54 0 30 54 +1 -1 30 +1 70 0 80 Before Insert(10) 0 10 0 +1 70 80 After Insert(10) 0 5 Operation on AVL Tree • • • • Case 3 Case 4 Case 5 Case 6 : Insert in left subtree for BF(T)=-1 : Insert in right subtree for BF(T)=+1 : Insert in left subtree for BF(T)=+1 : Insert in right subtree for BF(T)=-1 6 Operation on AVL Tree Single Rotation : LL, RR 54 0 30 +1 54 +1 70 0 80 0 30 +2 54 +2 70 LeftChild +1 80 88 0 30 0 80 0 Parent +1 70 0 88 RightChild 7 Operation on AVL Tree Double Rotation -1 10 0 5 0 20 30 60 0 40 0 -1 +1 80 50 -1 10 0 90 0 0 5 +1 20 60 -2 +1 80 0 +1 90 40 +1 0 30 50 55 Before Insert(55) Insert(55) 60 40 20 10 80 90 50 30 55 0 5 -1 10 -1 20 40 0 0 60 0 +1 +1 30 50 80 0 0 55 90 5 R1 R2 8
© Copyright 2026 Paperzz