1 / 19

B-Trees with Minimum=1 2-3 Trees

B-Trees with Minimum=1 2-3 Trees. Delete (T, X, success) /*Delete from tree T the item with key X. The operation fails if no such item. The flag success indicates whether the operation succeeds*/ //Attempt to locate I with search key X IF I is present THEN

rene
Télécharger la présentation

B-Trees with Minimum=1 2-3 Trees

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. B-Trees with Minimum=1 2-3 Trees Data Structures and Algorithms

  2. Delete (T, X, success) /*Delete from tree T the item with key X. The operation fails if no such item. The flag success indicates whether the operation succeeds*/ //Attempt to locate I with search key X IF I is present THEN swap item I into leaf L which contains the inorder successor of I /* deletion begins from leaf L */ IF L has no items THEN Fix (L) success := true ELSE success := false Data Structures and Algorithms

  3. Fix (N) /* N is a node with no item. Note, if N is an internal node, then it has one child. */ Let P be the parent of N. If N is the root, delete it and return. IF some sibling of N has two items THEN distribute items among N, the sibling, and P IF N is internal THEN move the appropriate child from the sibling to N ELSE /* must merge the node */ Choose an adjacent sibling S of N Bring the appropriate item down from P into S If N is internal THEN Move N’s child to S Delete node N If P is now without an item THEN Fix (P)

  4. Insert (T, newitem) /* Insert newitem into tree T */ Let X be the search key of new item Locate the leaf L in which X belongs Add newitem to L IF L now has three items THEN Split (L) Data Structures and Algorithms

  5. Split (N) /* Split node N which contains 3 items. Note that if N is internal then it has 4 children */ Let P be the parent of N /* if N is the root, then create a new node P */ Replace node N by two nodes, N1 and N2 Give N1 the item in N with the smallest search key value Give N2 the item in N with the largest search key value If N is an internal node THEN N1 becomes the parent of N’s two leftmost children N2 becomes the parent of N’s two rightmost children Send up to P the item in N with the middle search key value If P now has 3 items THEN Split (P)

  6. Insertion Given 50 30 70,90 10,20 40 60 80 100 Insertions are always at a leaf Insert 39 50 30 70,90 10,20 39,40 60 80 100 Data Structures and Algorithms

  7. Insert 38 50 30 70,90 10,20 38,39,40 60 80 100 illegal 50 30,39 70,90 10,20 38 40 60 80 100 Data Structures and Algorithms

  8. Insert 37 50 30,39 70,90 10,20 37,38 40 60 80 100 When the height grows it does so from the top. Data Structures and Algorithms

  9. Insert 36 50 30,39 70,90 10,20 36,37,38 40 60 80 100 illegal 37,50 30 39 10,20 36 38 40 50 30,37,39 10,20 36 38 40 illegal Data Structures and Algorithms

  10. Insert 35, 34, 33 37,50 30 10,20 35,36 37,50 30 10,20 34,35,36 illegal 37,50 30,35 10,20 34 36 h ALL leaves are at the same level Data Structures and Algorithms

  11. 37,50 30,35 39 70,90 10,20 33,34 36 38 40 60 80 100 h Data Structures and Algorithms

  12. Deletion Given 50 30 70,90 10,20 40 60 80 100 Delete 50 60 30 90 10,20 40 70,80 100 60 30 70,90 10,20 40 80 100 Data Structures and Algorithms

  13. Delete 100 60 30 90 10,20 40 70,80 60 30 80 10,20 40 70 90 Data Structures and Algorithms

  14. Delete 60 70 30 10,20 40 80,90 N 70 30 80 10,20 40 90 30 70 10,20 40 80,90 30,70 10,20 40 80,90 Data Structures and Algorithms

  15. Delete 70 30,80 10,20 40 90 Delete 80 30,90 10,20 40 30 10,20 40,90 Data Structures and Algorithms

  16. Given • 50 • 30 70,90 • 10,20 40 60 80 100 Delete 70 You always begin deletion from a leaf so swap with inorder successor. • 50 • 30 80,90 • 10,20 40 60 70 100 50 80,90 60 100 illegal Data Structures and Algorithms

  17. 50 90 60,80 100 50 30 90 10,20 40 60,80 100 Data Structures and Algorithms

  18. Delete 100 50 90 60,80 This leaf can spare a value 50 30 80 10,20 40 60 90 50 80 60 90 Data Structures and Algorithms

  19. Delete 80 50 30 90 10,20 40 60 50 30 90 10,20 40 60 80 50 30 10,20 40 60,90 Can‘t spare a value 30,50 10,20 40 60,90 Data Structures and Algorithms

More Related