Presentation is loading. Please wait.

Presentation is loading. Please wait.

Deleting from B- Trees Eric Nevala. Objective: Teach you the concept of deleting keys from a B-Tree 1. The concept of deleting from a B-Tree 2. A graphical.

Similar presentations


Presentation on theme: "Deleting from B- Trees Eric Nevala. Objective: Teach you the concept of deleting keys from a B-Tree 1. The concept of deleting from a B-Tree 2. A graphical."— Presentation transcript:

1 Deleting from B- Trees Eric Nevala

2 Objective: Teach you the concept of deleting keys from a B-Tree 1. The concept of deleting from a B-Tree 2. A graphical illustration of all the cases of deletion 3. Look at some implementations in C++ code 4. Do some practical exercises for practice (cards -> whiteboard)

3 The Concept You can delete a key entry from any node. ->Therefore, you must ensure that before/after deletion, the B-Tree maintains its properties. When deleting, you have to ensure that a node doesn’t get too small (minimum node size is T – 1). We prevent this by combining nodes together.

4 Run Time of a B-Tree The height grows in O(Lg N) time. t = degree h = height n = number of keys Run time is influenced by CPU speed and Disk I/O speeds Space used: O(2n) + sizeof(class/struct) Worst Case:

5 Lets look at an example: We’re given this valid B-Tree Source: Introduction to Algorithms, Thomas H. Cormen Note: T = 2

6 Simple Deletion Case 1: We delete “F” Source: Introduction to Algorithms, Thomas H. Cormen Result: We remove “F” from the leaf node. No further action needed.

7 When to just delete a key from a node: When a key is in a leaf node When deleting the key doesn’t make the leaf node smaller then the minimum allowable size (t-1)

8 Deleting and shifting Case 2a: We deleted “M” Source: Introduction to Algorithms, Thomas H. Cormen Result: We remove “M” from the parent node. Since there are four nodes and two letters, we move “L” to replace “M”. Now, the “N O” node has a parent again.

9 The rule: You must have n+1 child nodes. If you delete an intermediate node, you need to replace the missing node by promoting a child key. If you don’t go below the minimum t on the right, then take the right most node from the left branch, otherwise try the right left most node on the right branch.

10 Combining and Deleting Case 2c: Now, we delete “G” Source: Introduction to Algorithms, Thomas H. Cormen Result: First, we combine nodes “DE” and “JK”. Then, we push down “G” into the “DEJK” node and delete it as a leaf.

11 The rule Condition: You must delete a key. The key has a minimum number of nodes on the left and right branches. Action: Take the key to be deleted, move it down, and then combine the left and right branches. Then delete the key.

12 Check this out! Case 2b: Now, we delete “D”

13 The rule The recursion can’t descend down to node “CL” because it only has two keys, so “P” is pushed down to the end of “CL” and merged with “TX” to form “CLPTX”; Then, “D” is deleted as in the first rule.

14 Deleting “B” Before: After: Deleted “B”, Demoted “C”, Promoted “E”

15 The rule Conditions:  Deleting the key from the node would result in a node smaller then the minimum allowable size  The neighboring node has extra keys Actions:  Take the parent key and overwrite the node you’re deleting  Take the left most node from the right neighbor and promote it to the parent key Otherwise: combine nodes

16 Any questions so far? Next: C++ code implementation of B-Tree delete

17 The remove class member Source: “Data Structures and Program Design in C++”, Robert L. Kruse;

18 Recursive_remove class member

19 Remove_data Copy_in_predecessor

20 Restoring node structure

21 Move_left class member

22 Move_right class member

23 Combination Illustration

24 Combine class member

25 Quick Exercise Remove C, P and V from this B-Tree. Work with the guy next to you to compare and check your work. Which ever pair can correctly remove all three the fastest is awesome! You have five minutes

26 Pending any questions, we’ll move on to the white board.

27 Fair Use Statement Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright. In determining whether the use made of a work in any particular case is a fair use the factors to be considered shall include— the purpose and character of the use, including whether such use is of a commercial nature or is for nonprofit educational purposes; 1. the nature of the copyrighted work; 2. the amount and substantiality of the portion used in relation to the copyrighted work as a whole; and 3. the effect of the use upon the potential market for or value of the copyrighted work. The fact that a work is unpublished shall not itself bar a finding of fair use if such finding is made upon consideration of all the above factors.


Download ppt "Deleting from B- Trees Eric Nevala. Objective: Teach you the concept of deleting keys from a B-Tree 1. The concept of deleting from a B-Tree 2. A graphical."

Similar presentations


Ads by Google