B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries.

Slides:



Advertisements
Similar presentations
Data Structures Haim Kaplan and Uri Zwick November 2012 Lecture 5 B-Trees.
Advertisements

CSE332: Data Abstractions Lecture 9: B Trees Dan Grossman Spring 2010.
1 B trees Nodes have more than 2 children Each internal node has between k and 2k children and between k-1 and 2k-1 keys A leaf has between k-1 and 2k-1.
B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:
CS 206 Introduction to Computer Science II 12 / 01 / 2008 Instructor: Michael Eckmann.
CSE 326: Data Structures B-Trees Ben Lerner Summer 2007.
CS 206 Introduction to Computer Science II 11 / 24 / 2008 Instructor: Michael Eckmann.
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
Binary Tree. Binary Trees – An Informal Definition A binary tree is a tree in which no node can have more than two children Each node has 0, 1, or 2 children.
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
2-3 Trees Extended tree.  Tree in which all empty subtrees are replaced by new nodes that are called external nodes.  Original nodes are called internal.
B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:
B-Trees and Red Black Trees. Binary Trees B Trees spread data all over – Fine for memory – Bad on disks.
Comp 335 File Structures B - Trees. Introduction Simple indexes provided a way to directly access a record in an entry sequenced file thereby decreasing.
2-3 Trees Extended tree.  Tree in which all empty subtrees are replaced by new nodes that are called external nodes.  Original nodes are called internal.
B-Tree – Delete Delete 3. Delete 8. Delete
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
B-Trees ( Rizwan Rehman) Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory.
More Trees. Outline Tree B-Tree 2-3 Tree Tree Red-Black Tree.
Balanced Search Trees 2-3 Trees AVL Trees Red-Black Trees
COMP261 Lecture 23 B Trees.
Red Black Trees Colored Nodes Definition Binary search tree.
B-Trees B-Trees.
B/B+ Trees 4.7.
B-Tree Michael Tsai 2017/06/06.
Higher Order Tries Key = Social Security Number.
Multiway Search Trees Data may not fit into main memory
B-Trees B-Trees.
B-Trees .
B+-Trees j a0 k1 a1 k2 a2 … kj aj j = number of keys in node.
B-Trees B-Trees.
Indexing ? Why ? Need to locate the actual records on disk without having to read the entire table into memory.
B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries.
Chapter 11: Multiway Search Trees
Lecture 16 Multiway Search Trees
Multiway search trees and the (2,4)-tree
AVL DEFINITION An AVL tree is a binary search tree in which the balance factor of every node, which is defined as the difference between the heights of.
AVL Tree.
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
ITEC 2620M Introduction to Data Structures
B Tree Adhiraj Goel 1RV07IS004.
CMSC 341 Lecture 10 B-Trees Based on slides from Dr. Katherine Gibson.
Haim Kaplan and Uri Zwick November 2014
(2,4) Trees (2,4) Trees 1 (2,4) Trees (2,4) Trees
Chapter 6 Transform and Conquer.
Wednesday, April 18, 2018 Announcements… For Today…
Lecture 26 Multiway Search Trees Chapter 11 of textbook
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
BTrees.
Data Structures and Algorithms
Height Balanced Trees 2-3 Trees.
Multi-Way Search Trees
(2,4) Trees /26/2018 3:48 PM (2,4) Trees (2,4) Trees
B-Trees.
B-Tree.
(2,4) Trees (2,4) Trees (2,4) Trees.
Lecture 21: B-Trees Monday, Nov. 19, 2001.
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Mainly from Chapter 7 Adam Drozdek
CSIT 402 Data Structures II With thanks to TK Prasad
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
(2,4) Trees /24/2019 7:30 PM (2,4) Trees (2,4) Trees
(2,4) Trees (2,4) Trees (2,4) Trees.
AVL-Trees.
2-3 Trees Extended tree. Tree in which all empty subtrees are replaced by new nodes that are called external nodes. Original nodes are called internal.
B+-Trees j a0 k1 a1 k2 a2 … kj aj j = number of keys in node.
B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries.
B-Trees B-trees are characterized in the following way:
Presentation transcript:

B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries to overcome cache-miss penalties. May also be used internally to reduce cache misses and hence improve performance.

AVL Trees n = 230 = 109 (approx). 30 <= height <= 43. When the AVL tree resides on a disk, up to 43 disk access are made for a search. This takes up to (approx) 4 seconds. Not acceptable. 43 cache misses possible when searching memory resident AVL trees

Red-Black Trees n = 230 = 109 (approx). 30 <= height <= 60. When the red-black tree resides on a disk, up to 60 disk access are made for a search. This takes up to (approx) 6 seconds. Not acceptable.

m-way Search Trees Each node has up to m – 1 pairs and m children. m = 2 => binary search tree.

4-Way Search Tree 10 30 35 k > 35 k < 10 10 < k < 30 10 30 35 k > 35 k < 10 10 < k < 30 30 < k < 35

Maximum # Of Pairs Happens when all internal nodes are m-nodes. Full degree m tree. # of nodes = 1 + m + m2 + m3 + … + mh-1 = (mh – 1)/(m – 1). Each node has m – 1 pairs. So, # of pairs = mh – 1.

Capacity Of m-Way Search Tree Natural extension of 2-3 and 2-3-4 trees would leave worst case at m=2.

Definition Of B-Tree Definition assumes external nodes (extended m-way search tree). B-tree of order m. m-way search tree. Not empty => root has at least 2 children. Remaining internal nodes (if any) have at least ceil(m/2) children. External (or failure) nodes on same level. Alternative definition has pairs only in leaves; remaining nodes have keys only. Leaf-pushed B-tree or B+-tree.

2-3 And 2-3-4 Trees B-tree of order m. 2-3 tree is B-tree of order 3. m-way search tree. Not empty => root has at least 2 children. Remaining internal nodes (if any) have at least ceil(m/2) children. External (or failure) nodes on same level. 2-3 tree is B-tree of order 3. 2-3-4 tree is B-tree of order 4.

B-Trees Of Order 5 And 2 B-tree of order m. m-way search tree. Not empty => root has at least 2 children. Remaining internal nodes (if any) have at least ceil(m/2) children. External (or failure) nodes on same level. Not possible for an internal node in an extended tree to have only 1 child. B-tree of order 5 is 3-4-5 tree (root may be 2-node though). B-tree of order 2 is full binary tree.

Minimum # Of Pairs n = # of pairs. # of external nodes = n + 1. Height = h => external nodes on level h + 1. level # of nodes 1 1 >= 2 2 >= 2*ceil(m/2) 3 >= 2*ceil(m/2)h-1 h + 1 n + 1 >= 2*ceil(m/2)h-1, h >= 1

Minimum # Of Pairs n + 1 >= 2*ceil(m/2)h-1, h >= 1 m = 200. height # of pairs >= 199 2 >= 19,999 3 >= 2 * 106 – 1 4 >= 2 * 108 – 1 5 h <= log ceil(m/2) [(n+1)/2] + 1

Choice Of m Worst-case search time. search time m (time to fetch a node + time to search node) * height (a + b*m + c * log2m) * h where a, b and c are constants. m search time 50 400 Typically pick m so as to fill a block.

Insert 8 4 15 20 1 3 5 6 9 30 40 16 17 2-3 Tree. Insert 10, no problem. Insert 18? Insertion into a full leaf triggers bottom-up node splitting pass.

Split An Overfull Node m a0 p1 a1 p2 a2 … pm am ai is a pointer to a subtree. pi is a dictionary pair. ceil(m/2)-1 a0 p1 a1 p2 a2 … pceil(m/2)-1 aceil(m/2)-1 Node Splitting m-ceil(m/2) aceil(m/2) pceil(m/2)+1 aceil(m/2)+1 … pm am pceil(m/2) plus pointer to new node is inserted in parent.

Insert 8 4 15 20 1 3 5 6 9 30 40 16 17 Insert a pair with key = 2. 15 20 1 3 5 6 9 30 40 16 17 Insert a pair with key = 2. New pair goes into a 3-node.

Insert Into A Leaf 3-node Insert new pair so that the 3 keys are in ascending order. 1 2 3 Split overflowed node around middle key. 1 3 2 The code will do all 3 steps as one. Insert middle key and pointer to new node into parent.

Insert 8 4 15 20 1 3 5 6 9 30 40 16 17 Insert a pair with key = 2.

Insert Insert a pair with key = 2 plus a pointer into parent. 8 4 2 15 20 3 1 5 6 9 30 40 16 17 Insert a pair with key = 2 plus a pointer into parent.

Insert 15 20 8 1 2 4 5 6 30 40 9 16 17 3 Now, insert a pair with key = 18.

Insert Into A Leaf 3-node Insert new pair so that the 3 keys are in ascending order. 16 17 18 Split the overflowed node. 18 16 17 Insert middle key and pointer to new node into parent.

Insert 15 20 8 1 2 4 5 6 30 40 9 16 17 3 Insert a pair with key = 18.

Insert Insert a pair with key = 17 plus a pointer into parent. 8 17 2 4 15 20 18 1 3 5 6 9 16 30 40 Insert a pair with key = 17 plus a pointer into parent.

Insert Insert a pair with key = 17 plus a pointer into parent. 17 8 2 4 15 20 1 3 5 6 9 16 18 30 40 Insert a pair with key = 17 plus a pointer into parent.

Insert Now, insert a pair with key = 7. 1 2 4 5 6 30 40 9 3 16 15 18 2 4 5 6 30 40 9 3 16 15 18 20 8 17 Now, insert a pair with key = 7.

Insert Insert a pair with key = 6 plus a pointer into parent. 8 17 6 8 17 6 2 4 15 20 7 1 3 5 9 16 18 30 40 Insert a pair with key = 6 plus a pointer into parent.

Insert Insert a pair with key = 4 plus a pointer into parent. 8 17 4 6 8 17 4 6 2 15 20 5 7 9 16 18 30 40 1 3 Insert a pair with key = 4 plus a pointer into parent.

Insert Insert a pair with key = 8 plus a pointer into parent. 4 17 6 2 15 20 1 3 5 7 9 16 18 30 40 Insert a pair with key = 8 plus a pointer into parent. There is no parent. So, create a new root.

Insert 8 4 17 6 2 15 20 9 16 18 30 40 1 3 5 7 Height increases by 1.