1 / 13

Binary Search Tree (BST)

Binary Search Tree (BST). Binary Tree Sebagai Struktur File. Binary Search Tree. Struktur Binary Tree banyak digunakan untuk membantu memecahkan persoalan suatu algoritma, contohnya untuk memecahkan masalah organisasi file direct.

boyce
Télécharger la présentation

Binary Search Tree (BST)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Binary Search Tree (BST) Binary Tree Sebagai Struktur File

  2. Binary Search Tree • Struktur Binary Tree banyak digunakan untuk membantu memecahkan persoalan suatu algoritma, contohnya untuk memecahkan masalah organisasi file direct. • Penggunaan Binary Tree sebagai suatu struktur file yang disebut Binary Search Tree (BST). • Aturan Insert ke dalam File BST : < Node  Masuk Ke Kiri > Node  Masuk Ke Kanan

  3. 30 25 62 14 41 69 39 93 Contoh Insert ke File Binary Search Tree Key : 30, 62, 69, 41, 25, 39, 14, 93

  4. 14 25 30 39 41 62 69 93 Ketidakefisienan Binary Search Tree Key : 14, 25, 30, 39, 41, 62, 69, 93

  5. AVL TREE (Adelson, Velskii, Landis) BST Yang “Seimbang”

  6. Balance Factor B ---> level 1 A D ---> level 2 C F ---> level 3 E ---> level 4 • Subtree : Tree yang terbentuk disebelah kanan atau kiri dari suatu node. (Catatan : Node tsb disebut root subtree) • Tinggi subtree : Level node terbawah dari subtree dikurang level root subtree tsb • Balance Factor : Tinggi subtree kanan dikurang tinggi dari subtree kiri dari suatu node

  7. AVL Tree • Binary Search Tree yang memiliki aturan setiap node selalu memiliki balance factor 0, +1 atau -1 • Maka : setiap kali key baru diinsert ke dalam file, setiap node dilihat balance factornya • Apabila ada node yang balance factornya tidak 0, +1 atau -1 (tidak imbang) maka struktur file dilakukan transformasi : pemutaran dan atau penggeseran • Kemungkinan tidak imbang hanya 2 dan diselesaikan dengan solusi : Rotasi Tunggal dan Rotasi Ganda

  8. Y 0 X Rotasi kiri 0 C B A h h+1 h h+1 h Node Baru Kemungkinan Transformasi 1 (Rotasi Tunggal) X +2 +1 Y A +1 0 B C h h

  9. Y -2 0 Y X A -1 0 C B C B A h h+1 h h h+1 h Node Baru Kemungkinan Transformasi 1 (Rotasi Tunggal) X Rotasi kanan

  10. X X +2 -1 A Y Y D 0 0 B B C C h Z Z A A 0 +2 h h-1 h-1 h h h h-1 D D h h Node Baru h Kemungkinan Transformasi 2(Rotasi Ganda) X +1 +2 Y -1 0 Z +1 0 B C h-1 3 1 Geser kiri (X) 2 Geser kanan (Y)

  11. X X +1 -2 Y Y 0 0 Z Z -2 0 Kemungkinan Transformasi 2(Rotasi Ganda) X -2 Y +1 D A B C D Z -1 A B C D h-1 h h h h C h-1 B h A h h h-1 Node Baru 3 h 1 Geser kanan (X) 2 Geser kiri (Y)

  12. Transformasi Mana ? • Bila 2 node teratas tandanya sama maka gunakan Transformasi 1 (rotasi tunggal) • Bila 2 node teratas tandanya beda maka gunakan Transformasi 2 (rotasi ganda)

  13. CONTOH SOAL AVL-TREE Masukkan key berikut ke dalam AVL Tree : 51, 88, 92, 72, 41, 55, 35, 10

More Related