SlideShare a Scribd company logo
1 of 34
B-Trees And B+-Trees
Preview
• B-Tree Indexing
• B-Tree
• B-Tree Characteristics
• B-Tree Example
• B+-Tree
• B+-Tree Characteristics
• B+-Tree Example
B-Tree Index
• Standard use index in relational databases in a B-Tree index.
• Allows for rapid tree traversal searching through an upside-
down tree structure
• Reading a single record from a very large table using a B-Tree
index, can often result in a few block reads—even when the
index and table are millions of blocks in size.
• Any index structure other than a B-Tree index is subject to
overflow.
– Overflow is where any changes made to tables will not have records
added into the original index structure, but rather tacked on the end.
What is a B-Tree?
• B-tree is a specialized multiway tree designed
especially for use on disk.
• B-Tree consists of a root node, branch nodes
and leaf nodes containing the indexed field
values in the ending (or leaf) nodes of the
tree.
B-Tree Characteristics
• In a B-tree each node may contain a large number of keys
• B-tree is designed to branch out in a large number of
directions and to contain a lot of keys in each node so that
the height of the tree is relatively small
• Constraints that tree is always balanced
• Space wasted by deletion, if any, never becomes excessive
• Insert and deletions are simple processes
– Complicated only under special circumstances
-Insertion into a node that is already full or a deletion from a node
makes it less then half full
Characteristics of a B-Tree of Order P
• Within each node, K1 < K2 < .. < Kp-1
• Each node has at most p tree pointer
• Each node, except the root and leaf nodes, has at
least ceil(p/2) tree pointers, The root node has at
least two tree pointers unless it is the only node in
the tree.
• All leaf nodes are at the same level. Leaf node have
the same structure as internal nodes except that all
of their tree pointer Pi are null.
B-Tree Insertion
1) B-tree starts with a single root node (which is also a leaf node) at level
0.
2) Once the root node is full with p – 1 search key values and when
attempt to insert another entry in the tree, the root node splits into
two nodes at level 1.
3) Only the middle value is kept in the root node, and the rest of the
values are split evenly between the other two nodes.
4) When a nonroot node is full and a new entry is inserted into it, that
node is split into two nodes at the same level, and the middle entry is
moved to the parent node along with two pointers to the new split
nodes.
5) If the parent node is full, it is also split.
6) Splitting can propagate all the way to the root node, creating a new
level if the root is split.
B-Tree Deletion
1) If deletion of a value causes a node to be less than
half full, it is combined with it neighboring nodes,
and this can also propagate all the way to the root.
- Can reduce the number of tree levels.
*Shown by analysis and simulation that, after numerous random insertions and
deletions on a B-tree, the nodes are approximately 69 percent full when the
number of values in the tree stabilizes. If this happens , node splitting and
combining will occur only rarely, so insertion and deletion become quite
efficient.
B-tree of Order 5 Example
• All internal nodes have at least ceil(5 / 2) = ceil(2.5) = 3 children (and
hence at least 2 keys), other then the root node.
• The maximum number of children that a node can have is 5 (so that 4 is
the maximum number of keys)
• each leaf node must contain at least 2 keys
B-Tree Order 5 Insertion
• Originally we have an empty B-tree of order 5
• Want to insert C N G A H E K Q M F W L T Z D P R X Y S
• Order 5 means that a node can have a maximum of 5 children
and 4 keys
• All nodes other than the root must have a minimum of 2 keys
• The first 4 letters get inserted into the same node
B-Tree Order 5 Insertion Cont.
• When we try to insert the H, we find no room in this node,
so we split it into 2 nodes, moving the median item G up into
a new root node.
B-Tree Order 5 Insertion Cont.
• Inserting E, K, and Q proceeds without requiring
any splits
B-Tree Order 5 Insertion Cont.
• Inserting M requires a split
B-Tree Order 5 Insertion Cont.
• The letters F, W, L, and T are then added without
needing any split
B-Tree Order 5 Insertion Cont.
• When Z is added, the rightmost leaf must be split. The
median item T is moved up into the parent node
B-Tree Order 5 Insertion Cont.
• The insertion of D causes the leftmost leaf to be split. D happens to be
the median key and so is the one moved up into the parent node.
• The letters P, R, X, and Y are then added without any need of splitting
B-Tree Order 5 Insertion Cont.
• Finally, when S is added, the node with N, P, Q, and R splits, sending
the median Q up to the parent.
• The parent node is full, so it splits, sending the median M up to form
a new root node.
B-Tree Order 5 Deletion
• Initial B-Tree
B-Tree Order 5 Deletion Cont.
• Delete H
• Since H is in a leaf and the leaf has more than the
minimum number of keys, we just remove it.
B-Tree Order 5 Deletion Cont.
• Delete T.
• Since T is not in a leaf, we find its successor (the next item in ascending order),
which happens to be W.
• Move W up to replace the T. That way, what we really have to do is to delete W
from the leaf .
B+- Tree Characteristics
• Data records are only stored in the leaves.
• Internal nodes store just keys.
• Keys are used for directing a search to the proper
leaf.
• If a target key is less than a key in an internal node,
then the pointer just to its left is followed.
• If a target key is greater or equal to the key in the
internal node, then the pointer to its right is
followed.
• B+ Tree combines features of ISAM (Indexed
Sequential Access Method) and B Trees.
B+- Tree Characteristics Cont.
• Implemented on disk, it is likely that the
leaves contain key, pointer pairs where the
pointer field points to the record of data
associated with the key.
– allows the data file to exist separately from the B+
tree, which functions as an "index" giving an
ordering to the data in the data file.
B+- Tree Characteristics Cont.
• Very Fast Searching
• Insertion and deletion are expensive.
Formula n-order B+ tree with a height of h
• Maximum number of keys is nh
• Minimum number of keys is 2(n / 2)h−1
B+ tree of order 200 Example
• Leaves can each contain up to 199 keys
• Assuming that the root node has at least 100
children
• A 2 level B+ tree that meets these assumptions can
store about 9,900 records, since there are at least
100 leaves, each containing at least 99 keys.
• A 3 level B+ tree of this type can store about 1
million keys. A 4 level B+ tree can store up to about
100 million keys.
B+- Tree Structure
B+- Tree order 3 Insertion
• Insert value 5, 8, 1, 7
• Inserting value 5
• Since the node is empty, the value must be
placed in the leaf node.
B+- Tree Insertion Cont.
• Inserting value 8
• Since the node has room, we insert the new value.
B+- Tree Insertion Cont.
• Insert value 1
• Since the node is full, it must be split into two nodes.
• Each node is half full.
B+- Tree Insertion Cont.
• Inserting value 7.
B+- Tree Deletion
• Initial Tree
B+- Tree Deletion Cont.
• Delete Value 9
• Since the node is not less than half full, the tree is
correct.
B+- Tree Deletion Cont.
• Deleting value 8
• The node is less then half full, the values are redistributed
from the node on the left because it is full.
• The parent node is adjusted to reflect the change.
References
• Database System Concepts By Silberschatz, Korth,
Sudarshan
• Fundamentals of Database Systems By Elmasri,
Navathe

More Related Content

What's hot

BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]DEEPIKA T
 
Splay Tree Presentation Slides
Splay Tree Presentation SlidesSplay Tree Presentation Slides
Splay Tree Presentation SlidesMuhammad Shahbaz
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
Binary Search Tree (BST)
Binary Search Tree (BST)Binary Search Tree (BST)
Binary Search Tree (BST)M Sajid R
 
Lecture 14 splay tree
Lecture 14 splay treeLecture 14 splay tree
Lecture 14 splay treeAbirami A
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operationsKamran Zafar
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 

What's hot (20)

DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
b+ tree
b+ treeb+ tree
b+ tree
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
B tree
B treeB tree
B tree
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Binary tree
Binary tree Binary tree
Binary tree
 
Splay Tree Presentation Slides
Splay Tree Presentation SlidesSplay Tree Presentation Slides
Splay Tree Presentation Slides
 
Red black tree
Red black treeRed black tree
Red black tree
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
 
Binary Search Tree (BST)
Binary Search Tree (BST)Binary Search Tree (BST)
Binary Search Tree (BST)
 
Lecture 14 splay tree
Lecture 14 splay treeLecture 14 splay tree
Lecture 14 splay tree
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 

Viewers also liked

Viewers also liked (20)

B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
presentation on b tress. heap trees.hashing
presentation on b tress. heap trees.hashingpresentation on b tress. heap trees.hashing
presentation on b tress. heap trees.hashing
 
Tutorial 3 (b tree min heap)
Tutorial 3 (b tree min heap)Tutorial 3 (b tree min heap)
Tutorial 3 (b tree min heap)
 
1.9 b tree
1.9 b tree1.9 b tree
1.9 b tree
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Connected components and shortest path
Connected components and shortest pathConnected components and shortest path
Connected components and shortest path
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
B-Tree
B-TreeB-Tree
B-Tree
 
Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
 
TRIES_data_structure
TRIES_data_structureTRIES_data_structure
TRIES_data_structure
 
Application of tries
Application of triesApplication of tries
Application of tries
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
 
File organization 1
File organization 1File organization 1
File organization 1
 
FILE STRUCTURE IN DBMS
FILE STRUCTURE IN DBMSFILE STRUCTURE IN DBMS
FILE STRUCTURE IN DBMS
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
 
B tree
B treeB tree
B tree
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 

Similar to B trees and_b__trees

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
 
109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.pptssuser19bb13
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptxTekle12
 
Multiway Trees.ppt
Multiway Trees.pptMultiway Trees.ppt
Multiway Trees.pptAseemBhube1
 
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
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptxMouDhara1
 
Data structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxData structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxMalligaarjunanN
 
B tree ,B plus and graph
B tree ,B plus and graph B tree ,B plus and graph
B tree ,B plus and graph RaaviKapoor
 
Lecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptxLecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptxfizzaahmed9
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graphRai University
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graphRai University
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphRai University
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap treezia eagle
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10sumitbardhan
 

Similar to B trees and_b__trees (20)

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
 
109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptx
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
B+ tree.pptx
B+ tree.pptxB+ tree.pptx
B+ tree.pptx
 
Multiway Trees.ppt
Multiway Trees.pptMultiway Trees.ppt
Multiway Trees.ppt
 
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
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
 
Data structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxData structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptx
 
B tree ,B plus and graph
B tree ,B plus and graph B tree ,B plus and graph
B tree ,B plus and graph
 
Tree
TreeTree
Tree
 
Lecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptxLecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptx
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Tree
TreeTree
Tree
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 

Recently uploaded

While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in collegessuser7a7cd61
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our WorldEduminds Learning
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryJeremy Anderson
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024thyngster
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxBoston Institute of Analytics
 
Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Cathrine Wilhelmsen
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Seán Kennedy
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectBoston Institute of Analytics
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 
Machine learning classification ppt.ppt
Machine learning classification  ppt.pptMachine learning classification  ppt.ppt
Machine learning classification ppt.pptamreenkhanum0307
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfchwongval
 

Recently uploaded (20)

While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our World
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data Story
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
 
Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis Project
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 
Machine learning classification ppt.ppt
Machine learning classification  ppt.pptMachine learning classification  ppt.ppt
Machine learning classification ppt.ppt
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdf
 

B trees and_b__trees

  • 2. Preview • B-Tree Indexing • B-Tree • B-Tree Characteristics • B-Tree Example • B+-Tree • B+-Tree Characteristics • B+-Tree Example
  • 3. B-Tree Index • Standard use index in relational databases in a B-Tree index. • Allows for rapid tree traversal searching through an upside- down tree structure • Reading a single record from a very large table using a B-Tree index, can often result in a few block reads—even when the index and table are millions of blocks in size. • Any index structure other than a B-Tree index is subject to overflow. – Overflow is where any changes made to tables will not have records added into the original index structure, but rather tacked on the end.
  • 4. What is a B-Tree? • B-tree is a specialized multiway tree designed especially for use on disk. • B-Tree consists of a root node, branch nodes and leaf nodes containing the indexed field values in the ending (or leaf) nodes of the tree.
  • 5. B-Tree Characteristics • In a B-tree each node may contain a large number of keys • B-tree is designed to branch out in a large number of directions and to contain a lot of keys in each node so that the height of the tree is relatively small • Constraints that tree is always balanced • Space wasted by deletion, if any, never becomes excessive • Insert and deletions are simple processes – Complicated only under special circumstances -Insertion into a node that is already full or a deletion from a node makes it less then half full
  • 6. Characteristics of a B-Tree of Order P • Within each node, K1 < K2 < .. < Kp-1 • Each node has at most p tree pointer • Each node, except the root and leaf nodes, has at least ceil(p/2) tree pointers, The root node has at least two tree pointers unless it is the only node in the tree. • All leaf nodes are at the same level. Leaf node have the same structure as internal nodes except that all of their tree pointer Pi are null.
  • 7. B-Tree Insertion 1) B-tree starts with a single root node (which is also a leaf node) at level 0. 2) Once the root node is full with p – 1 search key values and when attempt to insert another entry in the tree, the root node splits into two nodes at level 1. 3) Only the middle value is kept in the root node, and the rest of the values are split evenly between the other two nodes. 4) When a nonroot node is full and a new entry is inserted into it, that node is split into two nodes at the same level, and the middle entry is moved to the parent node along with two pointers to the new split nodes. 5) If the parent node is full, it is also split. 6) Splitting can propagate all the way to the root node, creating a new level if the root is split.
  • 8. B-Tree Deletion 1) If deletion of a value causes a node to be less than half full, it is combined with it neighboring nodes, and this can also propagate all the way to the root. - Can reduce the number of tree levels. *Shown by analysis and simulation that, after numerous random insertions and deletions on a B-tree, the nodes are approximately 69 percent full when the number of values in the tree stabilizes. If this happens , node splitting and combining will occur only rarely, so insertion and deletion become quite efficient.
  • 9. B-tree of Order 5 Example • All internal nodes have at least ceil(5 / 2) = ceil(2.5) = 3 children (and hence at least 2 keys), other then the root node. • The maximum number of children that a node can have is 5 (so that 4 is the maximum number of keys) • each leaf node must contain at least 2 keys
  • 10. B-Tree Order 5 Insertion • Originally we have an empty B-tree of order 5 • Want to insert C N G A H E K Q M F W L T Z D P R X Y S • Order 5 means that a node can have a maximum of 5 children and 4 keys • All nodes other than the root must have a minimum of 2 keys • The first 4 letters get inserted into the same node
  • 11. B-Tree Order 5 Insertion Cont. • When we try to insert the H, we find no room in this node, so we split it into 2 nodes, moving the median item G up into a new root node.
  • 12. B-Tree Order 5 Insertion Cont. • Inserting E, K, and Q proceeds without requiring any splits
  • 13. B-Tree Order 5 Insertion Cont. • Inserting M requires a split
  • 14. B-Tree Order 5 Insertion Cont. • The letters F, W, L, and T are then added without needing any split
  • 15. B-Tree Order 5 Insertion Cont. • When Z is added, the rightmost leaf must be split. The median item T is moved up into the parent node
  • 16. B-Tree Order 5 Insertion Cont. • The insertion of D causes the leftmost leaf to be split. D happens to be the median key and so is the one moved up into the parent node. • The letters P, R, X, and Y are then added without any need of splitting
  • 17. B-Tree Order 5 Insertion Cont. • Finally, when S is added, the node with N, P, Q, and R splits, sending the median Q up to the parent. • The parent node is full, so it splits, sending the median M up to form a new root node.
  • 18. B-Tree Order 5 Deletion • Initial B-Tree
  • 19. B-Tree Order 5 Deletion Cont. • Delete H • Since H is in a leaf and the leaf has more than the minimum number of keys, we just remove it.
  • 20. B-Tree Order 5 Deletion Cont. • Delete T. • Since T is not in a leaf, we find its successor (the next item in ascending order), which happens to be W. • Move W up to replace the T. That way, what we really have to do is to delete W from the leaf .
  • 21. B+- Tree Characteristics • Data records are only stored in the leaves. • Internal nodes store just keys. • Keys are used for directing a search to the proper leaf. • If a target key is less than a key in an internal node, then the pointer just to its left is followed. • If a target key is greater or equal to the key in the internal node, then the pointer to its right is followed. • B+ Tree combines features of ISAM (Indexed Sequential Access Method) and B Trees.
  • 22. B+- Tree Characteristics Cont. • Implemented on disk, it is likely that the leaves contain key, pointer pairs where the pointer field points to the record of data associated with the key. – allows the data file to exist separately from the B+ tree, which functions as an "index" giving an ordering to the data in the data file.
  • 23. B+- Tree Characteristics Cont. • Very Fast Searching • Insertion and deletion are expensive.
  • 24. Formula n-order B+ tree with a height of h • Maximum number of keys is nh • Minimum number of keys is 2(n / 2)h−1
  • 25. B+ tree of order 200 Example • Leaves can each contain up to 199 keys • Assuming that the root node has at least 100 children • A 2 level B+ tree that meets these assumptions can store about 9,900 records, since there are at least 100 leaves, each containing at least 99 keys. • A 3 level B+ tree of this type can store about 1 million keys. A 4 level B+ tree can store up to about 100 million keys.
  • 27. B+- Tree order 3 Insertion • Insert value 5, 8, 1, 7 • Inserting value 5 • Since the node is empty, the value must be placed in the leaf node.
  • 28. B+- Tree Insertion Cont. • Inserting value 8 • Since the node has room, we insert the new value.
  • 29. B+- Tree Insertion Cont. • Insert value 1 • Since the node is full, it must be split into two nodes. • Each node is half full.
  • 30. B+- Tree Insertion Cont. • Inserting value 7.
  • 31. B+- Tree Deletion • Initial Tree
  • 32. B+- Tree Deletion Cont. • Delete Value 9 • Since the node is not less than half full, the tree is correct.
  • 33. B+- Tree Deletion Cont. • Deleting value 8 • The node is less then half full, the values are redistributed from the node on the left because it is full. • The parent node is adjusted to reflect the change.
  • 34. References • Database System Concepts By Silberschatz, Korth, Sudarshan • Fundamentals of Database Systems By Elmasri, Navathe