SlideShare a Scribd company logo
CS 6213 –
Advanced
Data
Structures
Lecture 4
BTREES
AN EXCELLENT DATA
STRUCTURE FOR DISK ACCESS
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well
 TA
Iswarya Parupudi
iswarya2291@gwmail.gwu.edu
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 2
LOGISTICS
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 3
CS 6213
Basics
Record /
Struct
Arrays / Linked
Lists / Stacks
/ Queues
Graphs / Trees
/ BSTs
Advanced
Trie, B-Tree
Splay Trees
R-Trees
Heaps and PQs
Union Find
 T.K.Prasad @ Purdue University
 Prof. Sin-Min Lee @ San Jose State University
 Rada Mihalcea @ University of North Texas
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 4
CREDITS
 Eventually you run out of RAM
 Plus, you need persistent storage
 Storing information on disk requires different
approach to efficiency
 Access time includes seek time and rotational delay
 Assuming that a disk spins at 3600 RPM, one
revolution occurs in 1/60 of a second, or 16.7ms.
 In other words, one disk access takes about the
same time as 200,000 instructions
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 5
MOTIVATION FOR B-TREES
 Assume that we use an AVL tree to store about 20 million
records
 log2 20,000,000 is about 24
 24 operations in terms of time is very small (4 GHz CPU,
etc).
 Normal data operation should take a few nanoseconds.
 However, a large binary tree in a file will cause lots of
different disk accesses
 24 * 16.7ms = 0.4 seconds
 Suddenly database query response time in seconds starts
making sense.
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 6
MOTIVATION FOR B-TREES (CONT.)
 We can’t improve the theoretical log n lower bound
on search for a binary tree
 But, the solution is to use more branches and thus
reduce the height of the tree!
 As branching increases, depth decreases
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 7
MOTIVATION FOR B-TREES (CONT.)
 Invented by Bayer and McCreight in 1972
 (Bayer also invented Red Black Trees)
 Definition is in terms of “order”, which is not always
clear, and different researchers mean different
things, but concepts remain the same.
 We will use Knuth’s terminology, where order
represents the maximum number of children.
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 8
B-TREES
 B-tree of order m (where m is an odd number) is an
m-way search tree, where keys partition the keys in
the children in the fashion of a search tree, with
following additional constraints:
1. [max] a node contains up to m – 1 keys and up to m children
(Actual number of keys is one less than the number of
children)
2. [min] all non-root nodes contain at least (m-1)/2 keys
3. [leaf level] all leaves are on the same level
4. [root] the root is either a leaf node, or it has at least two
children
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 9
B-TREE: DEFINITION
 While as per Knuth’s definition B-Tree of order 5 is a
tree where a node has a maximum of 5 children
nodes, the same tree may be defined as a [2,4] tree
in the sense that for any node, the number of keys is
between 2 and 4, both inclusive.
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 10
B-TREE: ALTERNATE DEFINITION
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 11
AN EXAMPLE B-TREE
51 6242
6 12
35
55 60 7564 9245
1 2 4 7 8 13 15 18 32
38 40 46 48 53
A B-tree of order 5:
• Root has at least 2 children
• Every other non-leaf node has at
least 2 keys and 3 children
• Each leaf has at least two keys
• All leaves are at same level.
61
 Different approach compared AVL Trees
 Don’t insert a new leaf, rather split the root and add
a new level above the root. This automatically
increases the height of ALL the leaves by one.
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 12
KEEPING THE HEIGHT SAME
 We want to construct a B-tree of order 5
 Suppose we start with an empty B-tree and keys
arrive in the following order: 1 12 8 2 25 5 14 28
17 7 52 16 48 68 3 26 29 53 55 45
 The first four items go into the root:
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 13
CONSTRUCTING A B-TREE
1 2 8 12
 To put the fifth item in the root would violate
constraint 1 (max)
 Therefore, when 25 arrives, we pick the middle key
to make a new root
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 14
CONSTRUCTING A B-TREE (CONT.)
1 2
8
12 25
 6, 14, 28 get added to the leaf nodes
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 15
CONSTRUCTING A B-TREE (CONT.)
1 2
8
12 146 25 28
 Adding 17 to the right leaf node would violate
constraint 1 (max), so we promote the middle key
(17) to the root and split the leaf
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 16
CONSTRUCTING A B-TREE (CONT.)
8 17
12 14 25 281 2 6
 7, 52, 16, 48 get added to the leaf nodes
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 17
CONSTRUCTING A B-TREE (CONT.)
8 17
12 14 25 281 2 6 16 48 527
 Adding 68 causes us to split the right most leaf,
promoting 48 to the root, and adding 3 causes us to
split the left most leaf, promoting 3 to the root; 26,
29, 53, 55 then go into the leaves
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 18
CONSTRUCTING A B-TREE (CONT.)
3 8 17 48
52 53 55 6825 26 28 291 2 6 7 12 14 16
 Adding 45 causes a split of
 But we observe that this does not cause the problem
of leaves at different heights.
 Rather, we promote 28 to go to the root.
 However, root is already full:
 So, this causes the root to split: 17 then becomes the
new root.
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 19
CONSTRUCTING A B-TREE (CONT.)
25 26 28 29
3 8 17 48
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 20
CONSTRUCTING A B-TREE (CONT.)
17
3 8 28 48
1 2 6 7 12 14 16 52 53 55 6825 26 29 45
 Attempt to insert the new key into a leaf
 If this would result in that leaf becoming too big,
split the leaf into two, promoting the middle key to
the leaf’s parent
 If this would result in the parent becoming too big,
split the parent into two, promoting the middle key
 This strategy might have to be repeated all the way
to the top
 If necessary, the root is split in two and the middle
key is promoted to a new root, making the tree one
level higher
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 21
SUMMARY: INSERTING INTO A B-TREE
 Insert the following keys to a 5-way B-tree:
 13, 27, 51, 3, 2, 14, 28, 1, 7, 71, 89, 37, 41, 44
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 22
EXERCISE IN INSERTING A B-TREE
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 23
REMOVAL FROM A B-TREE – 4
SCENARIOS
Scenario 1:
• Key to delete is a leaf node, and removing it doesn’t
cause that leaf node to have too few keys, then simply
remove the key to be deleted.
Scenario 2:
• Key to delete is not in a leaf and moving its successor or
predecessor does not cause the leaf node to have too
few keys. (We are guaranteed by the nature of a B-tree
that its predecessor or successor will be in a leaf.)
Scenario 3:
• Key to delete is a leaf node, but deleting it will have the
leaf to have too few keys, and we can borrow from an
adjacent leaf node.
Scenario 4:
• Key to delete is a leaf node, but deleting it will have the
leaf to have too few keys, and we cannot borrow from an
adjacent leaf node. Then the lacking leaf and one of its
neighbours can be combined with their shared parent
(the opposite of promoting a key) and the new leaf will
have the correct number of keys; if this step leave the
parent with too few keys then we repeat the process up
to the root itself, if required
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 24
SIMPLE LEAF DELETION
12 29 52
2 7 9 15 22 56 69 7231 43
We want to delete 2:
Since there are enough
keys in the node, we can just
delete it
Scenario1
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 25
SIMPLE LEAF DELETION (CONT.)
12 29 52
7 9 15 22 56 69 7231 43
That’s it, we deleted 2 and we
are done.
Scenario1
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 26
SIMPLE NON-LEAF DELETION
12 29 52
7 9 15 22 56 69 7231 43
Borrow the predecessor
or (in this case) successor
We want to delete 52. So, we
delete it, and see that the
successor can be moved up.
Scenario2
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 27
SIMPLE NON-LEAF DELETION (CONT.)
12 29 56
7 9 15 22 69 7231 43
Done. 52 is gone. 56
promoted to the non-leaf
node. Leaf nodes are still
meeting the min constraint.
Scenario2
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 28
TOO FEW KEYS IN NODE, BUT WE
CAN BORROW FROM SIBLINGS
12 29
7 9 15 22 695631 43
We want to delete 22 – that will
lead to too few keys in the node
(constraint 2). But we can borrow
from the adjacent node (via the
root).
Demote root key and
promote leaf key
Scenario3
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 29
TOO FEW KEYS IN NODE, BUT WE CAN
BORROW FROM SIBLINGS (CONT.)
12
297 9 15
31
695643
Done – 22 is gone. 29 came
down from the parent node, and
31 has gone up from the right
adjacent node.
Scenario3
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 30
TOO FEW KEYS IN NODE AND ITS
SIBLINGS
12 29 56
7 9 15 22 69 7231 43
We want to delete 72. This will lead to too few keys in
this node (constraint 2). We cannot borrow from the
adjacent sibling as it only has two. So, we need to
combine 31, 43, 56 and 69 into one node.
Scenario4
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 31
TOO FEW KEYS IN NODE AND ITS
SIBLINGS (CONT.)
12 29
7 9 15 22 695631 43
Done. 72 is gone. 31, 43, 56 and 69
combined into one node.
Scenario4
 The maximum number of items in a B-tree of order m and
height h:
root m – 1
level 1 m(m – 1)
level 2 m2(m – 1)
. . .
level h mh(m – 1)
 So, the total number of items is
(1 + m + m2 + m3 + … + mh)(m – 1) =
[(mh+1 – 1)/ (m – 1)] (m – 1) = mh+1 – 1
 When m = 5 and h = 2 this gives 53 – 1 = 124
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 32
ANALYSIS OF B-TREES
 Since there is a lower bound on the number of child
nodes of non-root nodes, a B-Tree is at least 50%
“full”.
 On average it is 75% full.
 The advantage of not being 100% full is that there
are empty spaces for insertions to happen without
going all the way to the root.
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 33
ANALYSIS OF B-TREES (CONT.)
 If m = 3, the specific case of B-Tree is called a 2-3
tree.
 For in memory access, 2-3 Tree may be a good
alternative to Red Black or AVL Tree.
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 34
2-3 TREES
 For small in-memory data structures, BSTs, Arrays, Hashmaps,
etc. work well.
 When we exceed the size of the RAM, or for persistence
reasons, the problem becomes quite different.
 The cost of each disc transfer is high but doesn't depend much on the
amount of data transferred, especially if adjacent items are transferred
 B-Trees are a great alternative (and very highly used) data
structure for disk accesses
 A B-Tree of order m allows each node to have from m/2 up to m children.
 There is flexibility that allows for gaps. This flexibility allows: (i) some
new elements to be stored in leaves with no other changes, and (ii) some
elements to be deleted easily without changes propagating to root
 If we use a B-tree of order 101, a B-tree of order 101 and height 3 can
hold 1014 – 1 items (approximately 100 million) and any item can be
accessed with 3 disc reads (assuming we hold the root in memory)
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 35
CONCLUSIONS &
RECAP OF CENTRAL IDEA
 If we take m = 3, we get a 2-3 tree, in which non-leaf
nodes have two or three children (i.e., one or two
keys)
 B-Trees are always balanced (since the leaves are all at the
same level), so 2-3 trees make a good type of balanced tree
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 36
CONCLUSIONS AND RECAP (CONT.)

More Related Content

What's hot

Tree
TreeTree
Tree
bhumish
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
Command Prompt., Inc
 
B+ Tree
B+ TreeB+ Tree
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
Shakila Mahjabin
 
Merge sort
Merge sortMerge sort
Merge sort
Soumen Santra
 
Data structure mind mapping
Data structure mind mapping Data structure mind mapping
Data structure mind mapping
Amr Hassan AbdUllah
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
introduction to_trees
introduction to_treesintroduction to_trees
introduction to_trees
Danish Aakash
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: Sharding
MongoDB
 
Binary trees
Binary treesBinary trees
Binary trees
Simratpreet Singh
 
Probabilistic data structure
Probabilistic data structureProbabilistic data structure
Probabilistic data structure
Thinh Dang
 
ClickHouse Intro
ClickHouse IntroClickHouse Intro
ClickHouse Intro
Yegor Andreenko
 
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its authorKaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Vivian S. Zhang
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
chauhankapil
 
How to Build a Fraud Detection Solution with Neo4j
How to Build a Fraud Detection Solution with Neo4jHow to Build a Fraud Detection Solution with Neo4j
How to Build a Fraud Detection Solution with Neo4j
Neo4j
 
Avl trees
Avl treesAvl trees
Avl trees
amna izzat
 
Fibonacci Heap
Fibonacci HeapFibonacci Heap
Fibonacci Heap
Anshuman Biswal
 

What's hot (20)

Tree
TreeTree
Tree
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
B+ Tree
B+ TreeB+ Tree
B+ Tree
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Data structure mind mapping
Data structure mind mapping Data structure mind mapping
Data structure mind mapping
 
Hash table
Hash tableHash table
Hash table
 
introduction to_trees
introduction to_treesintroduction to_trees
introduction to_trees
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: Sharding
 
Binary trees
Binary treesBinary trees
Binary trees
 
Probabilistic data structure
Probabilistic data structureProbabilistic data structure
Probabilistic data structure
 
ClickHouse Intro
ClickHouse IntroClickHouse Intro
ClickHouse Intro
 
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its authorKaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
How to Build a Fraud Detection Solution with Neo4j
How to Build a Fraud Detection Solution with Neo4jHow to Build a Fraud Detection Solution with Neo4j
How to Build a Fraud Detection Solution with Neo4j
 
Avl trees
Avl treesAvl trees
Avl trees
 
Fibonacci Heap
Fibonacci HeapFibonacci Heap
Fibonacci Heap
 

Viewers also liked

Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
Amrinder Arora
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Amrinder Arora
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Amrinder Arora
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
Amrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
Amrinder Arora
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
Amrinder Arora
 
08 B Trees
08 B Trees08 B Trees
08 B Trees
guestf7d226
 
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
Amrinder Arora
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Amrinder Arora
 

Viewers also liked (9)

Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
 
08 B Trees
08 B Trees08 B Trees
08 B Trees
 
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
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 

Similar to BTrees - Great alternative to Red Black, AVL and other BSTs

Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]
AKASHKUMAR1542
 
B tree by-jash acharya
B tree by-jash acharyaB tree by-jash acharya
B tree by-jash acharya
Jash Acharya
 
2-3 Tree, Everything you need to know
2-3 Tree,  Everything you need to know2-3 Tree,  Everything you need to know
2-3 Tree, Everything you need to know
Littbarski Santos
 
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
SadiaSharmin40
 
BTrees-fall2010.ppt
BTrees-fall2010.pptBTrees-fall2010.ppt
BTrees-fall2010.ppt
zalanmvb
 
B trees
B treesB trees
unit ii.pptx
unit ii.pptxunit ii.pptx
unit ii.pptx
ssuser24292c
 
Btree
BtreeBtree
Btree
jasscheema
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
RAtna29
 
B trees2
B trees2B trees2
B trees2
Aman Jatain
 
DATASTORAGE.pdf
DATASTORAGE.pdfDATASTORAGE.pdf
DATASTORAGE.pdf
Neheurevathy
 
DATASTORAGE
DATASTORAGEDATASTORAGE
DATASTORAGE
Neheurevathy
 
2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx
ujjwalmatoliya
 
DATASTORAGE.pptx
DATASTORAGE.pptxDATASTORAGE.pptx
DATASTORAGE.pptx
Neheurevathy
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Meghaj Mallick
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
Amrinder Arora
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
Core Condor
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Amrinder Arora
 
B+ tree
B+ treeB+ tree
B+ tree
Preethiadu
 
B trees
B treesB trees

Similar to BTrees - Great alternative to Red Black, AVL and other BSTs (20)

Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]
 
B tree by-jash acharya
B tree by-jash acharyaB tree by-jash acharya
B tree by-jash acharya
 
2-3 Tree, Everything you need to know
2-3 Tree,  Everything you need to know2-3 Tree,  Everything you need to know
2-3 Tree, Everything you need to know
 
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
 
BTrees-fall2010.ppt
BTrees-fall2010.pptBTrees-fall2010.ppt
BTrees-fall2010.ppt
 
B trees
B treesB trees
B trees
 
unit ii.pptx
unit ii.pptxunit ii.pptx
unit ii.pptx
 
Btree
BtreeBtree
Btree
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
 
B trees2
B trees2B trees2
B trees2
 
DATASTORAGE.pdf
DATASTORAGE.pdfDATASTORAGE.pdf
DATASTORAGE.pdf
 
DATASTORAGE
DATASTORAGEDATASTORAGE
DATASTORAGE
 
2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx
 
DATASTORAGE.pptx
DATASTORAGE.pptxDATASTORAGE.pptx
DATASTORAGE.pptx
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
 
B+ tree
B+ treeB+ tree
B+ tree
 
B trees
B treesB trees
B trees
 

More from Amrinder Arora

NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
Amrinder Arora
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
Amrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Amrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
Amrinder Arora
 
NP completeness
NP completenessNP completeness
NP completeness
Amrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
Amrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
Amrinder Arora
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
Amrinder Arora
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
Amrinder Arora
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
Amrinder Arora
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
Amrinder Arora
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsGraphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their Representations
Amrinder Arora
 
Learning to learn
Learning to learnLearning to learn
Learning to learn
Amrinder Arora
 

More from Amrinder Arora (18)

NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
NP completeness
NP completenessNP completeness
NP completeness
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsGraphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their Representations
 
Learning to learn
Learning to learnLearning to learn
Learning to learn
 

Recently uploaded

MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 

Recently uploaded (20)

MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 

BTrees - Great alternative to Red Black, AVL and other BSTs

  • 1. CS 6213 – Advanced Data Structures Lecture 4 BTREES AN EXCELLENT DATA STRUCTURE FOR DISK ACCESS
  • 2.  Instructor Prof. Amrinder Arora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well  TA Iswarya Parupudi iswarya2291@gwmail.gwu.edu L4 - BTrees CS 6213 - Advanced Data Structures - Arora 2 LOGISTICS
  • 3. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 3 CS 6213 Basics Record / Struct Arrays / Linked Lists / Stacks / Queues Graphs / Trees / BSTs Advanced Trie, B-Tree Splay Trees R-Trees Heaps and PQs Union Find
  • 4.  T.K.Prasad @ Purdue University  Prof. Sin-Min Lee @ San Jose State University  Rada Mihalcea @ University of North Texas L4 - BTrees CS 6213 - Advanced Data Structures - Arora 4 CREDITS
  • 5.  Eventually you run out of RAM  Plus, you need persistent storage  Storing information on disk requires different approach to efficiency  Access time includes seek time and rotational delay  Assuming that a disk spins at 3600 RPM, one revolution occurs in 1/60 of a second, or 16.7ms.  In other words, one disk access takes about the same time as 200,000 instructions L4 - BTrees CS 6213 - Advanced Data Structures - Arora 5 MOTIVATION FOR B-TREES
  • 6.  Assume that we use an AVL tree to store about 20 million records  log2 20,000,000 is about 24  24 operations in terms of time is very small (4 GHz CPU, etc).  Normal data operation should take a few nanoseconds.  However, a large binary tree in a file will cause lots of different disk accesses  24 * 16.7ms = 0.4 seconds  Suddenly database query response time in seconds starts making sense. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 6 MOTIVATION FOR B-TREES (CONT.)
  • 7.  We can’t improve the theoretical log n lower bound on search for a binary tree  But, the solution is to use more branches and thus reduce the height of the tree!  As branching increases, depth decreases L4 - BTrees CS 6213 - Advanced Data Structures - Arora 7 MOTIVATION FOR B-TREES (CONT.)
  • 8.  Invented by Bayer and McCreight in 1972  (Bayer also invented Red Black Trees)  Definition is in terms of “order”, which is not always clear, and different researchers mean different things, but concepts remain the same.  We will use Knuth’s terminology, where order represents the maximum number of children. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 8 B-TREES
  • 9.  B-tree of order m (where m is an odd number) is an m-way search tree, where keys partition the keys in the children in the fashion of a search tree, with following additional constraints: 1. [max] a node contains up to m – 1 keys and up to m children (Actual number of keys is one less than the number of children) 2. [min] all non-root nodes contain at least (m-1)/2 keys 3. [leaf level] all leaves are on the same level 4. [root] the root is either a leaf node, or it has at least two children L4 - BTrees CS 6213 - Advanced Data Structures - Arora 9 B-TREE: DEFINITION
  • 10.  While as per Knuth’s definition B-Tree of order 5 is a tree where a node has a maximum of 5 children nodes, the same tree may be defined as a [2,4] tree in the sense that for any node, the number of keys is between 2 and 4, both inclusive. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 10 B-TREE: ALTERNATE DEFINITION
  • 11. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 11 AN EXAMPLE B-TREE 51 6242 6 12 35 55 60 7564 9245 1 2 4 7 8 13 15 18 32 38 40 46 48 53 A B-tree of order 5: • Root has at least 2 children • Every other non-leaf node has at least 2 keys and 3 children • Each leaf has at least two keys • All leaves are at same level. 61
  • 12.  Different approach compared AVL Trees  Don’t insert a new leaf, rather split the root and add a new level above the root. This automatically increases the height of ALL the leaves by one. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 12 KEEPING THE HEIGHT SAME
  • 13.  We want to construct a B-tree of order 5  Suppose we start with an empty B-tree and keys arrive in the following order: 1 12 8 2 25 5 14 28 17 7 52 16 48 68 3 26 29 53 55 45  The first four items go into the root: L4 - BTrees CS 6213 - Advanced Data Structures - Arora 13 CONSTRUCTING A B-TREE 1 2 8 12
  • 14.  To put the fifth item in the root would violate constraint 1 (max)  Therefore, when 25 arrives, we pick the middle key to make a new root L4 - BTrees CS 6213 - Advanced Data Structures - Arora 14 CONSTRUCTING A B-TREE (CONT.) 1 2 8 12 25
  • 15.  6, 14, 28 get added to the leaf nodes L4 - BTrees CS 6213 - Advanced Data Structures - Arora 15 CONSTRUCTING A B-TREE (CONT.) 1 2 8 12 146 25 28
  • 16.  Adding 17 to the right leaf node would violate constraint 1 (max), so we promote the middle key (17) to the root and split the leaf L4 - BTrees CS 6213 - Advanced Data Structures - Arora 16 CONSTRUCTING A B-TREE (CONT.) 8 17 12 14 25 281 2 6
  • 17.  7, 52, 16, 48 get added to the leaf nodes L4 - BTrees CS 6213 - Advanced Data Structures - Arora 17 CONSTRUCTING A B-TREE (CONT.) 8 17 12 14 25 281 2 6 16 48 527
  • 18.  Adding 68 causes us to split the right most leaf, promoting 48 to the root, and adding 3 causes us to split the left most leaf, promoting 3 to the root; 26, 29, 53, 55 then go into the leaves L4 - BTrees CS 6213 - Advanced Data Structures - Arora 18 CONSTRUCTING A B-TREE (CONT.) 3 8 17 48 52 53 55 6825 26 28 291 2 6 7 12 14 16
  • 19.  Adding 45 causes a split of  But we observe that this does not cause the problem of leaves at different heights.  Rather, we promote 28 to go to the root.  However, root is already full:  So, this causes the root to split: 17 then becomes the new root. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 19 CONSTRUCTING A B-TREE (CONT.) 25 26 28 29 3 8 17 48
  • 20. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 20 CONSTRUCTING A B-TREE (CONT.) 17 3 8 28 48 1 2 6 7 12 14 16 52 53 55 6825 26 29 45
  • 21.  Attempt to insert the new key into a leaf  If this would result in that leaf becoming too big, split the leaf into two, promoting the middle key to the leaf’s parent  If this would result in the parent becoming too big, split the parent into two, promoting the middle key  This strategy might have to be repeated all the way to the top  If necessary, the root is split in two and the middle key is promoted to a new root, making the tree one level higher L4 - BTrees CS 6213 - Advanced Data Structures - Arora 21 SUMMARY: INSERTING INTO A B-TREE
  • 22.  Insert the following keys to a 5-way B-tree:  13, 27, 51, 3, 2, 14, 28, 1, 7, 71, 89, 37, 41, 44 L4 - BTrees CS 6213 - Advanced Data Structures - Arora 22 EXERCISE IN INSERTING A B-TREE
  • 23. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 23 REMOVAL FROM A B-TREE – 4 SCENARIOS Scenario 1: • Key to delete is a leaf node, and removing it doesn’t cause that leaf node to have too few keys, then simply remove the key to be deleted. Scenario 2: • Key to delete is not in a leaf and moving its successor or predecessor does not cause the leaf node to have too few keys. (We are guaranteed by the nature of a B-tree that its predecessor or successor will be in a leaf.) Scenario 3: • Key to delete is a leaf node, but deleting it will have the leaf to have too few keys, and we can borrow from an adjacent leaf node. Scenario 4: • Key to delete is a leaf node, but deleting it will have the leaf to have too few keys, and we cannot borrow from an adjacent leaf node. Then the lacking leaf and one of its neighbours can be combined with their shared parent (the opposite of promoting a key) and the new leaf will have the correct number of keys; if this step leave the parent with too few keys then we repeat the process up to the root itself, if required
  • 24. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 24 SIMPLE LEAF DELETION 12 29 52 2 7 9 15 22 56 69 7231 43 We want to delete 2: Since there are enough keys in the node, we can just delete it Scenario1
  • 25. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 25 SIMPLE LEAF DELETION (CONT.) 12 29 52 7 9 15 22 56 69 7231 43 That’s it, we deleted 2 and we are done. Scenario1
  • 26. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 26 SIMPLE NON-LEAF DELETION 12 29 52 7 9 15 22 56 69 7231 43 Borrow the predecessor or (in this case) successor We want to delete 52. So, we delete it, and see that the successor can be moved up. Scenario2
  • 27. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 27 SIMPLE NON-LEAF DELETION (CONT.) 12 29 56 7 9 15 22 69 7231 43 Done. 52 is gone. 56 promoted to the non-leaf node. Leaf nodes are still meeting the min constraint. Scenario2
  • 28. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 28 TOO FEW KEYS IN NODE, BUT WE CAN BORROW FROM SIBLINGS 12 29 7 9 15 22 695631 43 We want to delete 22 – that will lead to too few keys in the node (constraint 2). But we can borrow from the adjacent node (via the root). Demote root key and promote leaf key Scenario3
  • 29. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 29 TOO FEW KEYS IN NODE, BUT WE CAN BORROW FROM SIBLINGS (CONT.) 12 297 9 15 31 695643 Done – 22 is gone. 29 came down from the parent node, and 31 has gone up from the right adjacent node. Scenario3
  • 30. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 30 TOO FEW KEYS IN NODE AND ITS SIBLINGS 12 29 56 7 9 15 22 69 7231 43 We want to delete 72. This will lead to too few keys in this node (constraint 2). We cannot borrow from the adjacent sibling as it only has two. So, we need to combine 31, 43, 56 and 69 into one node. Scenario4
  • 31. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 31 TOO FEW KEYS IN NODE AND ITS SIBLINGS (CONT.) 12 29 7 9 15 22 695631 43 Done. 72 is gone. 31, 43, 56 and 69 combined into one node. Scenario4
  • 32.  The maximum number of items in a B-tree of order m and height h: root m – 1 level 1 m(m – 1) level 2 m2(m – 1) . . . level h mh(m – 1)  So, the total number of items is (1 + m + m2 + m3 + … + mh)(m – 1) = [(mh+1 – 1)/ (m – 1)] (m – 1) = mh+1 – 1  When m = 5 and h = 2 this gives 53 – 1 = 124 L4 - BTrees CS 6213 - Advanced Data Structures - Arora 32 ANALYSIS OF B-TREES
  • 33.  Since there is a lower bound on the number of child nodes of non-root nodes, a B-Tree is at least 50% “full”.  On average it is 75% full.  The advantage of not being 100% full is that there are empty spaces for insertions to happen without going all the way to the root. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 33 ANALYSIS OF B-TREES (CONT.)
  • 34.  If m = 3, the specific case of B-Tree is called a 2-3 tree.  For in memory access, 2-3 Tree may be a good alternative to Red Black or AVL Tree. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 34 2-3 TREES
  • 35.  For small in-memory data structures, BSTs, Arrays, Hashmaps, etc. work well.  When we exceed the size of the RAM, or for persistence reasons, the problem becomes quite different.  The cost of each disc transfer is high but doesn't depend much on the amount of data transferred, especially if adjacent items are transferred  B-Trees are a great alternative (and very highly used) data structure for disk accesses  A B-Tree of order m allows each node to have from m/2 up to m children.  There is flexibility that allows for gaps. This flexibility allows: (i) some new elements to be stored in leaves with no other changes, and (ii) some elements to be deleted easily without changes propagating to root  If we use a B-tree of order 101, a B-tree of order 101 and height 3 can hold 1014 – 1 items (approximately 100 million) and any item can be accessed with 3 disc reads (assuming we hold the root in memory) L4 - BTrees CS 6213 - Advanced Data Structures - Arora 35 CONCLUSIONS & RECAP OF CENTRAL IDEA
  • 36.  If we take m = 3, we get a 2-3 tree, in which non-leaf nodes have two or three children (i.e., one or two keys)  B-Trees are always balanced (since the leaves are all at the same level), so 2-3 trees make a good type of balanced tree L4 - BTrees CS 6213 - Advanced Data Structures - Arora 36 CONCLUSIONS AND RECAP (CONT.)