1 / 10

2-3 trees Damien Filiatrault 03-23-2004

2-3 trees Damien Filiatrault 03-23-2004. B-tree (data structure)

oma
Télécharger la présentation

2-3 trees Damien Filiatrault 03-23-2004

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. 2-3 trees Damien Filiatrault 03-23-2004

  2. B-tree (data structure) Definition: A balancedsearch tree in which every node has between m/2 and m children, where m>1 is a fixed integer. m is the order. The root may have as few as 2 children. This is a good structure if much of the tree is in slow memory (disk), since the height, and hence the number of accesses, can be kept small, say one or two, by picking a large m. source: http://www.nist.gov/dads/HTML/btree.html

  3. Why it is useful to use high-order b-trees saving application data on hard disk rather than in main memory:

  4. Example of a 2-3 tree: 4 : 10 3 : x 7 : x 13 : 27 1 3 4 7 10 13 27 2-3 trees are a data structure commonly used to implement ordered lists of records. A 2-3 tree is a tree satisfying the following requirements: - All internal nodes in the tree have either two or three children. - All leaves of the tree are at the same level.

  5. Same tree after adding the element: 8 4 : 10 Fork 3 : x 7 : 8 13 : 27 Leaf 1 3 4 7 8 10 13 27 Each fork contains the following indices: - the least element in child 2. - the least element in child 3 (if not empty).

  6. Same tree after adding the element: 9 4 : 10 3 : x 7 : 8 13 : 27 1 3 4 7 8 9 10 13 27 To insert a new leaf l in a 2-3 tree, locate the position where the new leaf should be inserted and add the new leaf to the tree. Call p the parent of the newly inserted leaf. If the number of children of p has increased from two to three, we still have a 2-3 tree and no further change is needed. If the number of children of p has increased from three to four, split p into two nodes with two children each, incrementing the number of children of p's parent. Proceed recursively up to the root of the tree, and, if needed, add a new root to augment the height of the tree by one. source: http://theory.lcs.mit.edu/~miccianc/inccrypto/23trees.html

  7. Insertion continued… 4 : 8 3 : x 7 : x 9 : x 13 : 27 1 3 4 7 8 9 10 13 27 To insert a new leaf l in a 2-3 tree, locate the position where the new leaf should be inserted and add the new leaf to the tree. Call p the parent of the newly inserted leaf. If the number of children of p has increased from two to three, we still have a 2-3 tree and no further change is needed. If the number of children of p has increased from three to four, split p into two nodes with two children each, incrementing the number of children of p's parent. Proceed recursively up to the root of the tree, and, if needed, add a new root to augment the height of the tree by one. source: http://theory.lcs.mit.edu/~miccianc/inccrypto/23trees.html

  8. Insertion completed. 8 : x 4 : x 10 : x 3 : x 7 : x 9 : x 13 : 27 1 3 4 7 8 9 10 13 27 To insert a new leaf l in a 2-3 tree, locate the position where the new leaf should be inserted and add the new leaf to the tree. Call p the parent of the newly inserted leaf. If the number of children of p has increased from two to three, we still have a 2-3 tree and no further change is needed. If the number of children of p has increased from three to four, split p into two nodes with two children each, incrementing the number of children of p's parent. Proceed recursively up to the root of the tree, and, if needed, add a new root to augment the height of the tree by one. source: http://theory.lcs.mit.edu/~miccianc/inccrypto/23trees.html

  9. Deletion: The deletion of a leaf from a 2-3 tree is performed analogously. First the leaf is located and removed. Call p the parent of the removed leaf. If the number of children of p has decreased from three to two, the tree is still 2-3. If the number of children of p has decreased from two to one, merge p with one of its siblings, possibly reducing the number of children of p's parent. Proceed recursively, up to the root of the tree. If at the end the root has degree one, romove it and make its child become root. source: http://theory.lcs.mit.edu/~miccianc/inccrypto/23trees.html

  10. Complexity: 1+log3n <= height(n) <= 1+log2n The time to search, insert or delete is O(log n). source: http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Tree/23tree/

More Related