1 / 9

B – Tree Bhargav Vadher (208) San Jose State University Computer Science Department

B – Tree Bhargav Vadher (208) San Jose State University Computer Science Department Feb 18 th , 2008. Agenda. Insertion of key in node. Deletion of key from node. Insertion of key in node. 1. Find specific location at leaf level for insertion, if there is room.

Download Presentation

B – Tree Bhargav Vadher (208) San Jose State University Computer Science Department

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 – Tree Bhargav Vadher (208) San Jose State University Computer Science Department Feb 18th , 2008

  2. Agenda • Insertion of key in node. • Deletion of key from node.

  3. Insertion of key in node 1. Find specific location at leaf level for insertion, if there is room. 2. If there is no room then divide the leaf into two leaf node. 2.1 Divide key-ptr pair such that ptr ≥ n/2. 3. recursion may be required if key-ptr pair need to insert at higher level. 3.1 If there is room at higher level, insert there or go ahead. 4. If there is insertion at root node. 4.1 Divide root  two internal node. 4.2 Make new root at upper level. Root must have only one key and two ptrs.

  4. 2 possibility for splitting node • Splitting at leaf node. suppose we have leaf node N keys = n = 3 ptrs = (n+1) = 4 and now we want to add (n+1)st key = K4. we have split the node N into two node N and new node M. Condition : (n+1)/2 ptrs would go with node N, and remaining with M.  N N M

  5. Splitting at internal node. suppose we have internal node = N keys = n = 3 ptrs = (n+1) = 4 and now we want to add (n+1)st key = K4. we have split the node N into two node N and new node M. Condition : (n+2)/2 ptrs would go with node N, and remaining with M.  N N M Example of Insertion node.

  6. Deletion of key from node • Find a leaf node N for deletion of key from a tree. • Delete the requested (key-ptr) pair. • After deletion • If node N satisfy the minimum ptr condition ( (n+1) / 2 ) We are done. Else (i). Borrow (key-ptr) from the sibling M. OR (ii). Combine the sibling M with N.

  7. Case 1: • Borrow (key-ptr) from sibling M. • Adjust the parent of M and N.  N M N M But what if, even sibling of N too, don’t have extra (key-ptr) pair. Move to case 2.

  8. Case 2: • Combine N with sibling M. Because M has lack of ptr & N has minimum ptr. • Adjust the key at parent of M and N. • Delete extra ptr from parent. • after deletion if parent has minimum ptr We are done with deletion Else Recursion in higher level. ……. …. N M N

  9. Q & A Thank you.

More Related