Upload
kanikanarang94
View
285
Download
10
Tags:
Embed Size (px)
DESCRIPTION
its a ppt to describe about B trees and B+trees
Citation preview
11
B+ - Tree & B - TreeB+ - Tree & B - Tree
By Phi Thong HoBy Phi Thong Ho
22
AgendaAgenda
B+ - Tree StructureB+ - Tree Structure
B+ - Tree UpdatesB+ - Tree Updates
B+ - Tree File OrganizationB+ - Tree File Organization
B - Tree Index FilesB - Tree Index Files
33
B+ - Tree StructureB+ - Tree Structure
A B+ - Tree is in the form of a balanced tree in A B+ - Tree is in the form of a balanced tree in which every path from the root of the tree to a which every path from the root of the tree to a leaf of the tree is the same length.leaf of the tree is the same length.
Each nonleaf node in the tree has between [n/2] Each nonleaf node in the tree has between [n/2] and n children, where n is fixed.and n children, where n is fixed.
B+ - Trees are good for searches, but cause B+ - Trees are good for searches, but cause some overhead issues in wasted space.some overhead issues in wasted space.
44
A typical node contains up to n – 1 search key A typical node contains up to n – 1 search key values K1, K2,…, Kn-1, and n pointers P1, P2,values K1, K2,…, Kn-1, and n pointers P1, P2,…, Pn. The search key values are kept in sorted …, Pn. The search key values are kept in sorted order.order.
P1 K1 P2 … Pn-1 Kn-1 Pn
55
The pointer Pi can point to either a file record or The pointer Pi can point to either a file record or a bucket of pointers which each point to a file a bucket of pointers which each point to a file record.record.
leaf node, n = 3leaf node, n = 3 Brighton Downtown
A – 212 Brighton 750
A – 101 Brighton 750
A – 212 Brighton 750...
66
Each leaf can hold up to n – 1 values and must Each leaf can hold up to n – 1 values and must contain at least [(n – 1) / 2] values.contain at least [(n – 1) / 2] values.
Nonleaf node pointers point to tree nodes (leaf Nonleaf node pointers point to tree nodes (leaf nodes). Nonleaf nodes can hold up to n pointers nodes). Nonleaf nodes can hold up to n pointers and must hold at least [n/2] pointers.and must hold at least [n/2] pointers.
i.e. n = 3i.e. n = 3 Perryridge
Mianus Redwood
Brighton Downtown Mianus Redwood Round Hill
Perryridge
77
B+ - Tree UpdatesB+ - Tree Updates
Insertion – If the new node has a search key that Insertion – If the new node has a search key that already exists in another leaf node, then it adds already exists in another leaf node, then it adds the new record to the file and a pointer to the the new record to the file and a pointer to the bucket of pointers. If the search key is different bucket of pointers. If the search key is different from all others, it is inserted in order.from all others, it is inserted in order.
Deletion – It removes the search key value from Deletion – It removes the search key value from the node.the node.
88
i.e. we are going to insert a node with a search i.e. we are going to insert a node with a search key value “Clearview”. We find that “Clearview” key value “Clearview”. We find that “Clearview” should be in the node with Brighton and should be in the node with Brighton and Downtown, so we must split the node.Downtown, so we must split the node.
i.e. n = 3i.e. n = 3 Perryridge
Downtown Mianus Redwood
Brighton Clearview Mianus Redwood Round Hill
Perryridge Downtown
99
i.e. Deletion of “Downtown” from slide #8.i.e. Deletion of “Downtown” from slide #8.
Perryridge
Mianus Redwood
Brighton Clearview Mianus Redwood Round Hill
Perryridge
1010
i.e. Deletion of “Perryridge” from slide #8i.e. Deletion of “Perryridge” from slide #8
Mianus
Downtown Redwood
Brighton Clearview Mianus Redwood Round Hill
Downtown
1111
B+ - Tree File OrganizationB+ - Tree File Organization
In a B+ - Tree file organization, the leaf nodes of the tree In a B+ - Tree file organization, the leaf nodes of the tree stores the actual record rather than storing pointers to stores the actual record rather than storing pointers to records.records.During insertion, the system locates the block that During insertion, the system locates the block that should contain the record. If there is enough free space should contain the record. If there is enough free space in the node then the system stores it. Otherwise the in the node then the system stores it. Otherwise the system splits the record in two and distributes the system splits the record in two and distributes the records.records.During deletion, the system first removes the record from During deletion, the system first removes the record from the block containing it. If the block becomes less than the block containing it. If the block becomes less than half full as a result, the records in the block are half full as a result, the records in the block are redistributed.redistributed.
1212
B+ - Tree File OrganizationB+ - Tree File Organization
1313
B - Tree Index FilesB - Tree Index Files
Similar to B+-tree, but B-tree allows search-key values to appear only once; eliminates redundant storage of search keys.
Search keys in nonleaf nodes appear nowhere else in the B-tree; an additional pointer field for each search key in a nonleaf node must be included.
Nonleaf node Nonleaf node –– pointers pointers BBii are the bucket or file record pointers. are the bucket or file record pointers.
1414
B – Tree Index FilesB – Tree Index Files
Advantages of B-Tree indices:Advantages of B-Tree indices: May use less tree nodes than a corresponding BMay use less tree nodes than a corresponding B++-Tree.-Tree. Sometimes possible to find search-key value before reaching Sometimes possible to find search-key value before reaching
leaf node.leaf node.
Disadvantages of B-Tree indices:Disadvantages of B-Tree indices: Only small fraction of all search-key values are found early Only small fraction of all search-key values are found early Non-leaf nodes are larger, so fan-out is reduced. Thus B-Trees Non-leaf nodes are larger, so fan-out is reduced. Thus B-Trees
typically have greater depth than corresponding typically have greater depth than corresponding BB++-Tree-Tree
Insertion and deletion more complicated than in BInsertion and deletion more complicated than in B++-Trees -Trees Implementation is harder than BImplementation is harder than B++-Trees.-Trees.
1515
Example of B – TreeExample of B – Tree