SlideShare a Scribd company logo
1 of 33
1
Multilevel Indexing and
B+ Trees
2
Indexed Sequential Files
• Provide a choice between two alternative
views of a file:
1. Indexed: the file can be seen as a set of
records that is indexed by key; or
2. Sequential: the file can be accessed
sequentially (physically contiguous
records), returning records in order by key.
3
Example of applications
• Student record system in a university:
– Indexed view: access to individual records
– Sequential view: batch processing when posting
grades
• Credit card system:
– Indexed view: interactive check of accounts
– Sequential view: batch processing of payments
4
The initial idea
• Maintain a sequence set:
– Group the records into blocks in a sorted way.
– Maintain the order in the blocks as records are
added or deleted through splitting,
concatenation, and redistribution.
• Construct a simple, single level index for
these blocks.
– Choose to build an index that contain the key
for the last record in each block.
5
Maintaining a Sequence Set
• Sorting and re-organizing after insertions and
deletions is out of question. We organize the
sequence set in the following way:
– Records are grouped in blocks.
– Blocks should be at least half full.
– Link fields are used to point to the preceding block and
the following block (similar to doubly linked lists)
– Changes (insertion/deletion) are localized into blocks
by performing:
• Block splitting when insertion causes overflow
• Block merging or redistribution when deletion causes
underflow.
6
Example: insertion
• Block size = 4
• Key : Last name
ADAMS … BIXBY … CARSON … COLE …
Block 1
• Insert “BAIRD …”:
ADAMS … BAIRD … BIXBY …
CARSON .. COLE …
Block 1
Block 2
7
Example: deletion
ADAMS … BAIRD … BIXBY … BOONE …
Block 1
BYNUM… CARSON .. CARTER ..
DENVER… ELLIS …
Block 2
Block 3
• Delete “DAVIS”, “BYNUM”, “CARTER”,
COLE… DAVIS
Block 4
8
Add an Index set
Key Block
BERNE 1
CAGE 2
DUTTON 3
EVANS 4
FOLK 5
GADDIS 6
9
Tree indexes
• This simple scheme is nice if the index fits in
memory.
• If index doesn’t fit in memory:
– Divide the index structure into blocks,
– Organize these blocks similarly building a tree
structure.
• Tree indexes:
– B Trees
– B+ Trees
– Simple prefix B+ Trees
– …
10
Separators
Block Range of Keys Separator
1 ADAMS-BERNE
BOLEN
2 BOLEN-CAGE
CAMP
3 CAMP-DUTTON
EMBRY
4 EMBRY-EVANS
FABER
5 FABER-FOLK
FOLKS
6 FOLKS-GADDIS
11
ADAMS-BERNE FOLKS-GADDIS
FABER-FOLK
BOLEN-CAGE
CAMP-DUTTON EMBRY-EVANS
BOLEN CAMP
EMBRY
FABER FOLKS
1
2
3
5
4 6
Index set
root
12
B Trees
• B-tree is one of the most important data structures
in computer science.
• What does B stand for? (Not binary!)
• B-tree is a multiway search tree.
• Several versions of B-trees have been proposed,
but only B+ Trees has been used with large files.
• A B+tree is a B-tree in which data records are in
leaf nodes, and faster sequential access is possible.
13
Formal definition of B+ Tree Properties
• Properties of a B+ Tree of order v :
– All internal nodes (except root) has at least v keys
and at most 2v keys .
– The root has at least 2 children unless it’s a leaf..
– All leaves are on the same level.
– An internal node with k keys has k+1 children
14
B+ tree: Internal/root node
structure
P0 K1 P1 K2 ……………… Pn-1 Kn Pn
 Requirements:
 K1 < K2 < … < Kn
 For any search key value K in the subtree pointed by Pi,
If Pi = P0, we require K < K1
If Pi = Pn, Kn  K
If Pi = P1, …, Pn-1, Ki < K  Ki+1
Each Pi is a pointer to a child node; each Ki is a search key value
# of search key values = n, # of pointers = n+1
15
 Pointer L points to the left neighbor; R points to
the right neighbor
 K1 < K2 < … < Kn
 v  n  2v (v is the order of this B+ tree)
 We will use Ki* for the pair <Ki, ri> and omit L and
R for simplicity
B+ tree: leaf node structure
L K1 r1 K2 ……………… Kn rn
R
16
Example: B+ tree with order of 1
• Each node must hold at least 1 entry, and at most
2 entries
10* 15* 20* 27* 33* 37* 40* 46* 51* 55* 63* 97*
20 33 51 63
40
Root
17
Example: Search in a B+ tree order 2
• Search: how to find the records with a given search key value?
– Begin at root, and use key comparisons to go to leaf
• Examples: search for 5*, 16*, all data entries >= 24* ...
– The last one is a range search, we need to do the sequential scan, starting from
the first leaf containing a value >= 24.
Root
17 24 30
2* 3* 5* 7* 14* 15* 19* 20* 22* 24* 27* 29* 33* 34* 38* 39*
13
18
B+ Trees in Practice
• Typical order: 100. Typical fill-factor: 67%.
– average fanout = 133 (i.e, # of pointers in internal
node)
• Can often hold top levels in buffer pool:
– Level 1 = 1 page = 8 Kbytes
– Level 2 = 133 pages = 1 Mbyte
– Level 3 = 17,689 pages = 133 MBytes
• Suppose there are 1,000,000,000 data entries.
– H = log133(1000000000/132) < 4
– The cost is 5 pages read
19
How to Insert a Data Entry into a
B+ Tree?
• Let’s look at several examples first.
20
Inserting 16*, 8* into Example B+ tree
Root
17 24 30
13
2* 3* 5* 7* 8*
2* 5* 7*
3*
17 24 30
13
8*
You overflow
One new child (leaf node)
generated; must add one more
pointer to its parent, thus one more
key value as well.
14* 15* 16*
21
Inserting 8* (cont.)
• Copy up the
middle value
(leaf split)
2* 3* 5* 7* 8*
5
Entry to be inserted in parent node.
(Note that 5 is
continues to appear in the leaf.)
s copied up and
13 17 24 30
You overflow!
5 13 17 24 30
22
(Note that 17 is pushed up and only
appears once in the index. Contrast
Entry to be inserted in parent node.
this with a leaf split.)
5 24 30
17
13
Insertion into B+ tree (cont.)
5 13 17 24 30
• Understand
difference
between copy-up
and push-up
• Observe how
minimum
occupancy is
guaranteed in
both leaf and
index pg splits.
We split this node, redistribute entries evenly,
and push up middle key.

23
Example B+ Tree After Inserting 8*
Notice that root was split, leading to increase in height.
2* 3*
Root
17
24 30
14* 15* 19* 20* 22* 24* 27* 29* 33* 34* 38* 39*
13
5
7*
5* 8*
24
Inserting a Data Entry into a B+ Tree:
Summary
• Find correct leaf L.
• Put data entry onto L.
– If L has enough space, done!
– Else, must split L (into L and a new node L2)
• Redistribute entries evenly, put middle key in L2
• copy up middle key.
• Insert index entry pointing to L2 into parent of L.
• This can happen recursively
– To split index node, redistribute entries evenly, but push up
middle key. (Contrast with leaf splits.)
• Splits “grow” tree; root split increases height.
– Tree growth: gets wider or one level taller at top.
25
Deleting a Data Entry from a B+
Tree
• Examine examples first …
26
Delete 19* and 20*
2* 3*
Root
17
24 30
14* 16* 19* 20* 22* 24* 27* 29* 33* 34* 38* 39*
13
5
7*
5* 8*
22*
27* 29*
22* 24*
Have we still forgot something?
27
Deleting 19* and 20* (cont.)
• Notice how 27 is copied up.
• But can we move it up?
• Now we want to delete 24
• Underflow again! But can we redistribute this time?
2* 3*
Root
17
30
14* 16* 33* 34* 38* 39*
13
5
7*
5* 8* 22* 24*
27
27* 29*
28
Deleting 24*
• Observe the two leaf
nodes are merged, and
27 is discarded from
their parent, but …
• Observe `pull down’ of
index entry (below).
30
22* 27* 29* 33* 34* 38* 39*
2* 3* 7* 14* 16* 22* 27* 29* 33* 34* 38* 39*
5* 8*
30
13
5 17
New root
29
Deleting a Data Entry from a B+ Tree:
Summary
• Start at root, find leaf L where entry belongs.
• Remove the entry.
– If L is at least half-full, done!
– If L has only d-1 entries,
• Try to re-distribute, borrowing from sibling (adjacent node
with same parent as L).
• If re-distribution fails, merge L and sibling.
• If merge occurred, must delete entry (pointing to L or
sibling) from parent of L.
• Merge could propagate to root, decreasing height.
30
Example of Non-leaf Re-distribution
• Tree is shown below during deletion of 24*. (What
could be a possible initial tree?)
• In contrast to previous example, can re-distribute entry
from left child of root to right child.
Root
13
5 17 20
22
30
14* 16* 17* 18* 20* 33* 34* 38* 39*
22* 27* 29*
21*
7*
5* 8*
3*
2*
31
After Re-distribution
• Intuitively, entries are re-distributed by `pushing
through’ the splitting entry in the parent node.
• It suffices to re-distribute index entry with key 20;
we’ve re-distributed 17 as well for illustration.
14* 16* 33* 34* 38* 39*
22* 27* 29*
17* 18* 20* 21*
7*
5* 8*
2* 3*
Root
13
5
17
30
20 22
32
Terminology
• Bucket Factor: the number of records which can
fit in a leaf node.
• Fan-out : the average number of children of an
internal node.
• A B+tree index can be used either as a primary
index or a secondary index.
– Primary index: determines the way the records are
actually stored (also called a sparse index)
– Secondary index: the records in the file are not
grouped in buckets according to keys of secondary
indexes (also called a dense index)
33
Summary
• Tree-structured indexes are ideal for range-
searches, also good for equality searches.
• B+ tree is a dynamic structure.
– Inserts/deletes leave tree height-balanced; High fanout (F)
means depth rarely more than 3 or 4.
– Almost always better than maintaining a sorted file.
– Typically, 67% occupancy on average.
– If data entries are data records, splits can change rids!
• Most widely used index in database management
systems because of its versatility. One of the most
optimized components of a DBMS.

More Related Content

Similar to btrees.ppt ttttttttttttttttttttttttttttt

Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmRAtna29
 
16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structure16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structureSadiaSharmin40
 
[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexingAnusAhmad
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil duttAnil Dutt
 
Furnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree StructuresFurnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree Structuresijceronline
 
B TREE ( a to z concept ) in data structure or DBMS
B TREE ( a to z concept ) in data structure  or DBMSB TREE ( a to z concept ) in data structure  or DBMS
B TREE ( a to z concept ) in data structure or DBMSMathkeBhoot
 
BTrees-fall2010.ppt
BTrees-fall2010.pptBTrees-fall2010.ppt
BTrees-fall2010.pptzalanmvb
 
B-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structureB-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structuressuser19bb13
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__treesmeghu123
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data StructureOm Prakash
 
LEC 7-DS ALGO(expression and huffman).pdf
LEC 7-DS  ALGO(expression and huffman).pdfLEC 7-DS  ALGO(expression and huffman).pdf
LEC 7-DS ALGO(expression and huffman).pdfMuhammadUmerIhtisham
 

Similar to btrees.ppt ttttttttttttttttttttttttttttt (20)

B trees
B treesB trees
B trees
 
Indexing.ppt
Indexing.pptIndexing.ppt
Indexing.ppt
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
 
16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structure16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structure
 
[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil dutt
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Furnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree StructuresFurnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree Structures
 
B TREE ( a to z concept ) in data structure or DBMS
B TREE ( a to z concept ) in data structure  or DBMSB TREE ( a to z concept ) in data structure  or DBMS
B TREE ( a to z concept ) in data structure or DBMS
 
B trees
B treesB trees
B trees
 
BTrees-fall2010.ppt
BTrees-fall2010.pptBTrees-fall2010.ppt
BTrees-fall2010.ppt
 
A41001011
A41001011A41001011
A41001011
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
B-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structureB-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structure
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
b-tree.ppt
b-tree.pptb-tree.ppt
b-tree.ppt
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
302 B+Tree Ind Hash
302 B+Tree Ind Hash302 B+Tree Ind Hash
302 B+Tree Ind Hash
 
LEC 7-DS ALGO(expression and huffman).pdf
LEC 7-DS  ALGO(expression and huffman).pdfLEC 7-DS  ALGO(expression and huffman).pdf
LEC 7-DS ALGO(expression and huffman).pdf
 

More from RAtna29

PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnPatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnRAtna29
 
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnNLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnRAtna29
 
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbLexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbRAtna29
 
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzlecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzRAtna29
 
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNModel-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNRAtna29
 
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyTF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyRAtna29
 
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhexing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhRAtna29
 
redblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxredblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxRAtna29
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbRAtna29
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
avltrees.ppt unit 4 ppts for the university exam
avltrees.ppt unit 4 ppts for the university examavltrees.ppt unit 4 ppts for the university exam
avltrees.ppt unit 4 ppts for the university examRAtna29
 
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuavltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuRAtna29
 
nlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmnlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmRAtna29
 

More from RAtna29 (13)

PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnPatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnNLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbLexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
 
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzlecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNModel-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
 
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyTF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
 
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhexing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
redblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxredblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptx
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
avltrees.ppt unit 4 ppts for the university exam
avltrees.ppt unit 4 ppts for the university examavltrees.ppt unit 4 ppts for the university exam
avltrees.ppt unit 4 ppts for the university exam
 
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuavltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
 
nlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmnlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmm
 

Recently uploaded

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 

Recently uploaded (20)

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 

btrees.ppt ttttttttttttttttttttttttttttt

  • 2. 2 Indexed Sequential Files • Provide a choice between two alternative views of a file: 1. Indexed: the file can be seen as a set of records that is indexed by key; or 2. Sequential: the file can be accessed sequentially (physically contiguous records), returning records in order by key.
  • 3. 3 Example of applications • Student record system in a university: – Indexed view: access to individual records – Sequential view: batch processing when posting grades • Credit card system: – Indexed view: interactive check of accounts – Sequential view: batch processing of payments
  • 4. 4 The initial idea • Maintain a sequence set: – Group the records into blocks in a sorted way. – Maintain the order in the blocks as records are added or deleted through splitting, concatenation, and redistribution. • Construct a simple, single level index for these blocks. – Choose to build an index that contain the key for the last record in each block.
  • 5. 5 Maintaining a Sequence Set • Sorting and re-organizing after insertions and deletions is out of question. We organize the sequence set in the following way: – Records are grouped in blocks. – Blocks should be at least half full. – Link fields are used to point to the preceding block and the following block (similar to doubly linked lists) – Changes (insertion/deletion) are localized into blocks by performing: • Block splitting when insertion causes overflow • Block merging or redistribution when deletion causes underflow.
  • 6. 6 Example: insertion • Block size = 4 • Key : Last name ADAMS … BIXBY … CARSON … COLE … Block 1 • Insert “BAIRD …”: ADAMS … BAIRD … BIXBY … CARSON .. COLE … Block 1 Block 2
  • 7. 7 Example: deletion ADAMS … BAIRD … BIXBY … BOONE … Block 1 BYNUM… CARSON .. CARTER .. DENVER… ELLIS … Block 2 Block 3 • Delete “DAVIS”, “BYNUM”, “CARTER”, COLE… DAVIS Block 4
  • 8. 8 Add an Index set Key Block BERNE 1 CAGE 2 DUTTON 3 EVANS 4 FOLK 5 GADDIS 6
  • 9. 9 Tree indexes • This simple scheme is nice if the index fits in memory. • If index doesn’t fit in memory: – Divide the index structure into blocks, – Organize these blocks similarly building a tree structure. • Tree indexes: – B Trees – B+ Trees – Simple prefix B+ Trees – …
  • 10. 10 Separators Block Range of Keys Separator 1 ADAMS-BERNE BOLEN 2 BOLEN-CAGE CAMP 3 CAMP-DUTTON EMBRY 4 EMBRY-EVANS FABER 5 FABER-FOLK FOLKS 6 FOLKS-GADDIS
  • 11. 11 ADAMS-BERNE FOLKS-GADDIS FABER-FOLK BOLEN-CAGE CAMP-DUTTON EMBRY-EVANS BOLEN CAMP EMBRY FABER FOLKS 1 2 3 5 4 6 Index set root
  • 12. 12 B Trees • B-tree is one of the most important data structures in computer science. • What does B stand for? (Not binary!) • B-tree is a multiway search tree. • Several versions of B-trees have been proposed, but only B+ Trees has been used with large files. • A B+tree is a B-tree in which data records are in leaf nodes, and faster sequential access is possible.
  • 13. 13 Formal definition of B+ Tree Properties • Properties of a B+ Tree of order v : – All internal nodes (except root) has at least v keys and at most 2v keys . – The root has at least 2 children unless it’s a leaf.. – All leaves are on the same level. – An internal node with k keys has k+1 children
  • 14. 14 B+ tree: Internal/root node structure P0 K1 P1 K2 ……………… Pn-1 Kn Pn  Requirements:  K1 < K2 < … < Kn  For any search key value K in the subtree pointed by Pi, If Pi = P0, we require K < K1 If Pi = Pn, Kn  K If Pi = P1, …, Pn-1, Ki < K  Ki+1 Each Pi is a pointer to a child node; each Ki is a search key value # of search key values = n, # of pointers = n+1
  • 15. 15  Pointer L points to the left neighbor; R points to the right neighbor  K1 < K2 < … < Kn  v  n  2v (v is the order of this B+ tree)  We will use Ki* for the pair <Ki, ri> and omit L and R for simplicity B+ tree: leaf node structure L K1 r1 K2 ……………… Kn rn R
  • 16. 16 Example: B+ tree with order of 1 • Each node must hold at least 1 entry, and at most 2 entries 10* 15* 20* 27* 33* 37* 40* 46* 51* 55* 63* 97* 20 33 51 63 40 Root
  • 17. 17 Example: Search in a B+ tree order 2 • Search: how to find the records with a given search key value? – Begin at root, and use key comparisons to go to leaf • Examples: search for 5*, 16*, all data entries >= 24* ... – The last one is a range search, we need to do the sequential scan, starting from the first leaf containing a value >= 24. Root 17 24 30 2* 3* 5* 7* 14* 15* 19* 20* 22* 24* 27* 29* 33* 34* 38* 39* 13
  • 18. 18 B+ Trees in Practice • Typical order: 100. Typical fill-factor: 67%. – average fanout = 133 (i.e, # of pointers in internal node) • Can often hold top levels in buffer pool: – Level 1 = 1 page = 8 Kbytes – Level 2 = 133 pages = 1 Mbyte – Level 3 = 17,689 pages = 133 MBytes • Suppose there are 1,000,000,000 data entries. – H = log133(1000000000/132) < 4 – The cost is 5 pages read
  • 19. 19 How to Insert a Data Entry into a B+ Tree? • Let’s look at several examples first.
  • 20. 20 Inserting 16*, 8* into Example B+ tree Root 17 24 30 13 2* 3* 5* 7* 8* 2* 5* 7* 3* 17 24 30 13 8* You overflow One new child (leaf node) generated; must add one more pointer to its parent, thus one more key value as well. 14* 15* 16*
  • 21. 21 Inserting 8* (cont.) • Copy up the middle value (leaf split) 2* 3* 5* 7* 8* 5 Entry to be inserted in parent node. (Note that 5 is continues to appear in the leaf.) s copied up and 13 17 24 30 You overflow! 5 13 17 24 30
  • 22. 22 (Note that 17 is pushed up and only appears once in the index. Contrast Entry to be inserted in parent node. this with a leaf split.) 5 24 30 17 13 Insertion into B+ tree (cont.) 5 13 17 24 30 • Understand difference between copy-up and push-up • Observe how minimum occupancy is guaranteed in both leaf and index pg splits. We split this node, redistribute entries evenly, and push up middle key. 
  • 23. 23 Example B+ Tree After Inserting 8* Notice that root was split, leading to increase in height. 2* 3* Root 17 24 30 14* 15* 19* 20* 22* 24* 27* 29* 33* 34* 38* 39* 13 5 7* 5* 8*
  • 24. 24 Inserting a Data Entry into a B+ Tree: Summary • Find correct leaf L. • Put data entry onto L. – If L has enough space, done! – Else, must split L (into L and a new node L2) • Redistribute entries evenly, put middle key in L2 • copy up middle key. • Insert index entry pointing to L2 into parent of L. • This can happen recursively – To split index node, redistribute entries evenly, but push up middle key. (Contrast with leaf splits.) • Splits “grow” tree; root split increases height. – Tree growth: gets wider or one level taller at top.
  • 25. 25 Deleting a Data Entry from a B+ Tree • Examine examples first …
  • 26. 26 Delete 19* and 20* 2* 3* Root 17 24 30 14* 16* 19* 20* 22* 24* 27* 29* 33* 34* 38* 39* 13 5 7* 5* 8* 22* 27* 29* 22* 24* Have we still forgot something?
  • 27. 27 Deleting 19* and 20* (cont.) • Notice how 27 is copied up. • But can we move it up? • Now we want to delete 24 • Underflow again! But can we redistribute this time? 2* 3* Root 17 30 14* 16* 33* 34* 38* 39* 13 5 7* 5* 8* 22* 24* 27 27* 29*
  • 28. 28 Deleting 24* • Observe the two leaf nodes are merged, and 27 is discarded from their parent, but … • Observe `pull down’ of index entry (below). 30 22* 27* 29* 33* 34* 38* 39* 2* 3* 7* 14* 16* 22* 27* 29* 33* 34* 38* 39* 5* 8* 30 13 5 17 New root
  • 29. 29 Deleting a Data Entry from a B+ Tree: Summary • Start at root, find leaf L where entry belongs. • Remove the entry. – If L is at least half-full, done! – If L has only d-1 entries, • Try to re-distribute, borrowing from sibling (adjacent node with same parent as L). • If re-distribution fails, merge L and sibling. • If merge occurred, must delete entry (pointing to L or sibling) from parent of L. • Merge could propagate to root, decreasing height.
  • 30. 30 Example of Non-leaf Re-distribution • Tree is shown below during deletion of 24*. (What could be a possible initial tree?) • In contrast to previous example, can re-distribute entry from left child of root to right child. Root 13 5 17 20 22 30 14* 16* 17* 18* 20* 33* 34* 38* 39* 22* 27* 29* 21* 7* 5* 8* 3* 2*
  • 31. 31 After Re-distribution • Intuitively, entries are re-distributed by `pushing through’ the splitting entry in the parent node. • It suffices to re-distribute index entry with key 20; we’ve re-distributed 17 as well for illustration. 14* 16* 33* 34* 38* 39* 22* 27* 29* 17* 18* 20* 21* 7* 5* 8* 2* 3* Root 13 5 17 30 20 22
  • 32. 32 Terminology • Bucket Factor: the number of records which can fit in a leaf node. • Fan-out : the average number of children of an internal node. • A B+tree index can be used either as a primary index or a secondary index. – Primary index: determines the way the records are actually stored (also called a sparse index) – Secondary index: the records in the file are not grouped in buckets according to keys of secondary indexes (also called a dense index)
  • 33. 33 Summary • Tree-structured indexes are ideal for range- searches, also good for equality searches. • B+ tree is a dynamic structure. – Inserts/deletes leave tree height-balanced; High fanout (F) means depth rarely more than 3 or 4. – Almost always better than maintaining a sorted file. – Typically, 67% occupancy on average. – If data entries are data records, splits can change rids! • Most widely used index in database management systems because of its versatility. One of the most optimized components of a DBMS.