SlideServe
Menu
Préférences
© SlideServe · v2026

AVL Tree ,B-tree

sachi avatar
24 diapositives · 1.2K Views · Oct 20, 2014

AVL Tree ,B-tree. วิวัฒน์ ชินนาทศิริกุล. AVL Tree (Adelson-Velskii and Landis Tree). นิยามของ AVL Tree 1. เป็น binary search tree 2. เป็น Balanced tree Balanced tree หมายถึง Tree ที่มีคุณสมบัติดังนี้คือ ทุกโหนดใน tree ต้องมีค่าน้ำหนักประจำโหนด เป็น -1 , 0 หรือ 1 เท่านั้น

AVL Tree ,B-tree - slide 1
01 / 24AVL Tree ,B-tree
1 / 17

Télécharger la présentation

AVL Tree ,B-tree
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. AVL Tree ,B-tree วิวัฒน์ ชินนาทศิริกุล

  2. AVL Tree(Adelson-Velskii and Landis Tree) • นิยามของ AVL Tree 1.เป็น binary search tree 2. เป็น Balanced tree • Balanced treeหมายถึง Tree ที่มีคุณสมบัติดังนี้คือ ทุกโหนดใน tree ต้องมีค่าน้ำหนักประจำโหนด เป็น -1 , 0 หรือ 1 เท่านั้น น้ำหนักของโหนด R = ความสูงของ TL - ความสูงของ TR

  3. ตัวอย่างการตรวจสอบ AVL Tree โหนดที่บรรจุข้อมูล 12 มีความสูงเท่ากับ 1-3 = -2 โหนดที่บรรจุข้อมูล 7 มีความสูงเท่ากับ 0-2 = -2 โหนดที่บรรจุข้อมูล 20 มีความสูงเท่ากับ 2-1 = 1 12 7 20 15 43 5

  4. 25 11 14 43 3 24 8 32 56 1 18 34 41 3 74 29 86 13 72 81 คำถาม Tree ที่กำหนดด้านล่างเป็น AVL Tree หรือไม่ รูป B รูป A

  5. สาเหตุที่ทำให้ Tree ไม่สมดุลย์ (Unbalanced tree) 1. Left of Leftเกิดเมื่อมีการแทรกโหนดเข้าไปด้าน sub-tree ฝั่งซ้ายของโหนดลูกทางซ้าย เกิด Imbalance 11 11 5 24 5 24 3 7 3 7 2 เดิมต้นไม้สมดุลย์ ต้นไม้ไม่สมดุลย์

  6. 2. Right of Rightเกิดเมื่อมีการแทรกโหนดเข้าไปด้าน sub-tree ฝั่งขวาของโหนดลูกทางขวา เกิด Imbalance 11 11 5 24 5 24 15 45 15 45 เดิมต้นไม้สมดุลย์ ต้นไม้ไม่สมดุลย์ 82

  7. 3.Right of Left เกิดเมื่อมีการแทรกโหนดเข้าไปด้าน sub-tree ฝั่งขวาของโหนดลูกทางซ้าย เกิด Imbalance 11 11 5 24 5 24 3 10 3 10 6

  8. 4. Left of Right เกิดเมื่อมีการแทรกโหนดเข้าไปด้าน sub-tree ฝั่งขวาของโหนดลูกทางซ้าย เกิด Imbalance 11 11 5 24 5 24 15 45 15 45 18

  9. การทำ Balancing Tree 1. Single rotation การหมุน 1 ครั้ง ใช้กรณีเกิด Left of Left และ Right of Right 2. Double rotation การหมุน 2 ครั้ง ใช้กรณีเกิด Right of Left และ Left of Right

  10. 1. Single rotation : rotate right C B B A C A

  11. ตัวอย่าง 24 11 11 5 24 5 28 28 10 56 49 10 2 12 49 2 12 30 56 30

  12. 11 5 5 24 3 11 3 7 24 2 7 2

  13. 2. Single rotation : rotate left A B B A C C

  14. ตัวอย่าง 4 12 12 4 20 20 13 13 26 5 20 5 2 7 26 2 7 20 38 38

  15. 24 11 45 5 15 82 11 5 24 15 45 82

  16. 3. Double rotation: left of right A B C A C B

  17. ตัวอย่าง 11 15 5 24 11 24 15 45 5 18 45 18

  18. 4. Double rotation: right of left C B A A C B

  19. ตัวอย่าง 11 10 5 24 5 11 3 10 3 6 24 6

  20. ตัวอย่าง จงสร้าง AVL Tree จากข้อมูลที่นำเข้ามาตามลำดับดังต่อไปนี้ 23, 54, 34, 2, 14, 7, 26, 16, 87, 21, 9

  21. โครงสร้างข้อมูลแบบ B-Tree เป็นการจัดให้โครงสร้างต้นไม้อยู่ในสภาพสมดุล วิธีการหนึ่งที่เรียกว่า Balanced Order n Multiway Search Tree หรือ B-Tree (ตั้งชื่อตามผู้พัฒนาขึ้นคือ Buyer) คุณสมบัติของ B-Tree order m มีดังนี้ • โหนดราก ถ้ามีลูกหลาน จะต้องมีอย่างน้อย 2 โหนด • โหนดอื่นๆที่ไม่ใช่โหนดราก หรือโหนดใบ จะมีลูกไม่น้อยกว่า m/2 • โหนดใบอยู่ในระดับเดียวกัน • 4. B-Tree order m อาจเรียก (m-1)-m tree เช่น B-Tree order 3 • อาจเรียกว่า 2-3 Tree

  22. ตัวอย่าง B-tree order 3 หรือ 2-3 Tree 20 35 40 7 15 30 10 17 25 32 37 42 43 3 5

  23. ตัวอย่าง จงสร้าง 2-3 Tree จากข้อมูลต่อไปนี้ 5 6 7 2 8 1 3 0 9 4

  24. แบบฝึกหัด 1. จงสร้าง AVL Tree จากข้อมูลที่กำหนดให้ต่อไปนี้ 5, 23, 57, 8, 12, 45, 21, 36, 28, 4, 22, 13, 27 2. กำหนด 2-3 Tree ดังภาพ 15 6 19 25 5 17 7 8 20 21 29 30 จงนำข้อมูลต่อไปนี้ 9 , 10 , 22 , 40 , 12 ,45 , 50 แทรกลง 2-3 Tree