1 Binary Trees Binary Trees Binary Search Trees Binary Search Trees CSE 30331 Lecture 13 –Trees.
Nikhat b+ trees ppt
-
Upload
nikihat-maniyar -
Category
Education
-
view
127 -
download
14
Transcript of Nikhat b+ trees ppt
A Dynamic Index structure
B + TREES:
SUB-TOPICS What is a B+ Tree? Format of a Node Search Insert Delete Duplicates
What is a B+ Tree? The B+ tree search structure is a balanced tree
in which the internal nodes direct the search and the leaf nodes contain the data entries.
OR
A B+ tree is a balanced tree in which every path from the root of the tree to a leaf is of the same length, and each non leaf node of the tree has between [n/2] and [n] children, where n is fixed for a particular tree.
What is a B+ Tree? Structure of a B+ Tree
What is a B+ Tree?
It contains index pages and data pages. The capacity of a leaf has to be 50% or more. For example: if n = 4, then the key for each node is between 2 to 4. The index page will be 4 + 1 = 5.
Example of a B+ tree with four keys (n = 4) looks like this:
What is a B+ Tree?
FORMAT OF A NODE The format of a node is
the same as for ISAM as shown below:
FORMAT OF A NODE Non-leaf nodes with m index entries
contain m + 1 pointers to children. Pointer Pi points to a sub tree in which all key values K are such that Ki ≤ K<Ki+1.
As special cases, Po points to a tree in which all key values are less than K1, and Pm points to a tree in which all key values are greater than or equal to Km. For leaf nodes, entries are denoted as k∗, as usual.
SEARCH The Searching time in a B+ tree is much
shorter than most of other kinds of trees. For example: To search a data in one million
key-values, a balanced binary requires about 20 block reads, in contrast only 4 block reads is required in B+ Tree.
SEARCH Since no structure change in
a B+ tree during a searching process, so just compare the key value with the data in the tree, then give the result back.
For example: find the value 15, and 45 in below tree.
SEARCHResult: 1. For the value of 45, not found. 2. For the value of 15, return the position
where the pointer located
INSERTSince insert a value into a B+ tree may cause
the tree unbalance, so rearrange the tree if needed.
Example #1: Insert 28 into the below tree.
INSERTResult:
INSERTExample #2: insert 70 into below tree
INSERTProcess: split the
tree
50 55 60 65 70
50 55 60 65 70
Violate the 50%
rule, split the leaf
INSERTResult: chose the middle key 60, and place it
in the index page between 50 and 75.
DELETESame as insertion, the tree has to be rebuild if the deletion result violate the rule of B+ tree.
Example #1: delete 70 from the tree
60 65 This is
OK.
DELETEResult:
DELETEExample #2: delete 25 from below tree, but 25
appears in the index page.
28 30
But…
This is OK.
DELETEResult: replace 28 in the index page.
Add 28
DELETEExample #3: delete 60 from the below tree
65
50 55 65 Violet
the 50% rule
DELETEResult: delete 60 from the index page and
combine the rest of index pages.
DUPLICATES The search, insertion, and deletion algorithms ignore
the issue of duplicate keys, that is, several data entries with the same key value.
how duplicates can be handled? We handle them just like any other entries and several
leaf pages may contain entries with a given key value. To retrieve all data entries with a given key value, we
must search for the left-most data entry with the given key value and then possibly retrieve more than one leaf page (using the leaf sequence pointers).