M-ary Search Tree. B-Trees. B-Trees. Solution: B-Trees. B-Tree: Example. B-Tree Properties. Maximum branching factor of M Complete tree has height =

Similar documents
M-ary Search Tree. B-Trees. Solution: B-Trees. B-Tree: Example. B-Tree Properties. B-Trees (4.7 in Weiss)

CSE 326: Data Structures B-Trees and B+ Trees

CSE 326: Data Structures Lecture #11 B-Trees

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

Background: disk access vs. main memory access (1/2)

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25

Multiway searching. In the worst case of searching a complete binary search tree, we can make log(n) page faults Everyone knows what a page fault is?

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

CS350: Data Structures B-Trees

B-Trees. Disk Storage. What is a multiway tree? What is a B-tree? Why B-trees? Insertion in a B-tree. Deletion in a B-tree

Motivation for B-Trees

(2,4) Trees. 2/22/2006 (2,4) Trees 1

CS 350 : Data Structures B-Trees

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

B-Trees. Version of October 2, B-Trees Version of October 2, / 22

CSE 373 OCTOBER 25 TH B-TREES

Lecture 11: Multiway and (2,4) Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Multiway Search Trees. Multiway-Search Trees (cont d)

CSE 530A. B+ Trees. Washington University Fall 2013

C SCI 335 Software Analysis & Design III Lecture Notes Prof. Stewart Weiss Chapter 4: B Trees

Binary Search Trees. Analysis of Algorithms

Comp 335 File Structures. B - Trees

Material You Need to Know

CSE332: Data Abstractions Lecture 7: B Trees. James Fogarty Winter 2012

What is a Multi-way tree?

Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Balanced Search Trees

Algorithms. Deleting from Red-Black Trees B-Trees

Augmenting Data Structures

B-Trees and External Memory

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

B-Trees and External Memory

CS Fall 2010 B-trees Carola Wenk

The B-Tree. Yufei Tao. ITEE University of Queensland. INFS4205/7205, Uni of Queensland

CMPS 2200 Fall 2017 B-trees Carola Wenk

Physical Level of Databases: B+-Trees

Tree-Structured Indexes

Search Trees - 1 Venkatanatha Sarma Y

Data Structures and Algorithms

Introduction to Indexing 2. Acknowledgements: Eamonn Keogh and Chotirat Ann Ratanamahatana

Multi-Way Search Trees

CS F-11 B-Trees 1

Tree-Structured Indexes

Multi-Way Search Trees

Binary Trees

Extra: B+ Trees. Motivations. Differences between BST and B+ 10/27/2017. CS1: Java Programming Colorado State University

Trees. Reading: Weiss, Chapter 4. Cpt S 223, Fall 2007 Copyright: Washington State University

Chapter 12: Indexing and Hashing (Cnt(

Problem. Indexing with B-trees. Indexing. Primary Key Indexing. B-trees: Example. B-trees. primary key indexing

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Database Systems. File Organization-2. A.R. Hurson 323 CS Building

amiri advanced databases '05

Find the block in which the tuple should be! If there is free space, insert it! Otherwise, must create overflow pages!

THE B+ TREE INDEX. CS 564- Spring ACKs: Jignesh Patel, AnHai Doan

CSIT5300: Advanced Database Systems

EE 368. Weeks 5 (Notes)

B+ Tree Review. CSE332: Data Abstractions Lecture 10: More B Trees; Hashing. Can do a little better with insert. Adoption for insert

CS127: B-Trees. B-Trees

CS 310 B-trees, Page 1. Motives. Large-scale databases are stored in disks/hard drives.

B-Trees. Based on materials by D. Frey and T. Anastasio

Multi-way Search Trees! M-Way Search! M-Way Search Trees Representation!

B-Trees & its Variants

(2,4) Trees Goodrich, Tamassia. (2,4) Trees 1

Tree-Structured Indexes

Introduction. Choice orthogonal to indexing technique used to locate entries K.

Principles of Data Management. Lecture #5 (Tree-Based Index Structures)

Search Trees. COMPSCI 355 Fall 2016

B-Trees. CS321 Spring 2014 Steve Cutchin

More B-trees, Hash Tables, etc. CS157B Chris Pollett Feb 21, 2005.

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Sample Exam 1 Questions

Intro to DB CHAPTER 12 INDEXING & HASHING

Tree-Structured Indexes

Chapter 11: Indexing and Hashing

Tree-Structured Indexes ISAM. Range Searches. Comments on ISAM. Example ISAM Tree. Introduction. As for any index, 3 alternatives for data entries k*:

Organizing Spatial Data

Tree-Structured Indexes

CARNEGIE MELLON UNIVERSITY DEPT. OF COMPUTER SCIENCE DATABASE APPLICATIONS

Chapter 12: Indexing and Hashing. Basic Concepts

Recall: Properties of B-Trees

10/23/12. Outline. Part 6. Trees (3) Example: A B-tree of degree 5. B-tree of degree m. Inserting 55. Inserting 55. B-Trees External Methods

Tree-Structured Indexes. Chapter 10

Lecture 3: B-Trees. October Lecture 3: B-Trees

2-3 and Trees. COL 106 Shweta Agrawal, Amit Kumar, Dr. Ilyas Cicekli

B-Trees. Introduction. Definitions

Chapter 12: Indexing and Hashing

Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Design and Analysis of Algorithms Lecture- 9: B- Trees

Section 4 SOLUTION: AVL Trees & B-Trees

CISC 235: Topic 4. Balanced Binary Search Trees

Tree-Structured Indexes. A Note of Caution. Range Searches ISAM. Example ISAM Tree. Introduction

Multi-way Search Trees

Spring 2017 B-TREES (LOOSELY BASED ON THE COW BOOK: CH. 10) 1/29/17 CS 564: Database Management Systems, Jignesh M. Patel 1

CE 221 Data Structures and Algorithms

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs

Tree-Structured Indexes

CS350: Data Structures Red-Black Trees

Trees. CSE 373 Data Structures

Transcription:

M-ary Search Tree B-Trees Section 4.7 in Weiss Maximum branching factor of M Complete tree has height = # disk accesses for find: Runtime of find: 2 Solution: B-Trees specialized M-ary search trees Each node has (up to) M-1 keys: subtree between two keys x and y contains leaves with values v such that x v < y Pick branching factor M such that each node takes one full {page, block} of memory 7 12 21 x< x<7 7 x<12 12 x<21 21 x B-Trees What makes them disk-friendly? 1. Many keys stored in a node All brought to memory/cache in one access! 2. Internal nodes contain only keys; Only leaf nodes contain keys and actual data The tree structure can be loaded into memory irrespective of data object size Data actually resides in disk 4 B-Tree: Example B-Tree Properties 1 2 AB xg B-Tree with M = 4 (# pointers in internal node) and L = 4 (# data items in leaf) 6 9 10 11 12 1 17 10 40 1 20 0 0 20 2 0 2 6 40 42 0 60 70 Data is stored at the leaves All leaves are at the same depth and contain between L/2 and L data items Internal nodes store up to M-1 keys Internal nodes have between M/2 and M children Root (special case) has between 2 and M children (or root could be a leaf) Data objects, that I ll ignore in slides Note: All leaves at the same depth! These are technically B + -Trees 6 1

B-Tree with M = 4 and L = 4 Example, Again 10 40 1 20 0 0 B-trees vs. AVL trees Suppose we have 100 million items (100,000,000): Depth of AVL Tree Depth of B+ Tree with M = 128, L = 64 1 2 10 11 12 20 2 40 42 6 9 1 17 0 2 6 0 60 70 (Only showing keys, but leaves also have data!) 7 8 Building a B-Tree Splitting the Root Too many keys in a leaf! The empty B-Tree Insert() Insert() Insert(1) 1 1 So, split the leaf. And create a new root 1 Now, Insert(1)? 9 10 1 Overflowing leaves Insert(9) Insert() 1 9 9 1 9 Too many keys in a leaf! 1 9 So, split the leaf. And add a new child 9 1 9 Propagating Splits 9 1 9 Insert() 1 9 9 Split the leaf, but no space in parent! Create a new root 1 9 Add new child 9 11 So, split the node. 12 2

Insertion Algorithm After More Routine Inserts 1. Insert the key in its leaf 2. If the leaf ends up with L+1 Split the leaf into two nodes: original with (L+1)/2 items new one with (L+1)/2 items Add the new child to the parent If the parent ends up with M+1 This makes the tree deeper!. If an internal node ends up with M+1 Split the node into two nodes: original with (M+1)/2 items new one with (M+1)/2 items Add the new child to the parent If the parent ends up with M+1 4. Split an overflowed root in two and hang the new nodes under a new root 9 1 9 Insert() Insert() 9 1 9 1 Deletion 1. Delete item from leaf 2. Update keys of ancestors if necessary Deletion and Adoption Delete()? 9 Delete(9) 1 1 1 9 1 So, borrow from a sibling What could go wrong? 1 1 16 Does Adoption Always Work? What if the sibling doesn t have enough for you to borrow from? e.g. you have L/2-1 and sibling has L/2? Deletion and Merging Delete()? 1 1 And no sibling with surplus! 17 But now an internal node has too few subtrees! 1 So, delete the leaf 18

Deletion with Propagation (More Adoption) A Bit More Adoption 1 Adopt a neighbor 1 1 Delete(1) (adopt a sibling) 19 20 Pulling out the Root Delete() And no sibling with surplus! So, delete the leaf; merge Pulling out the Root (continued) The root has just one subtree! Simply make the one child the new root! But now the root has just one subtree! A node has too few subtrees and no neighbor with surplus! Delete the node 21 22 Deletion Algorithm Deletion Slide Two 1. Remove the key from its leaf 2. If the leaf ends up with fewer than L/2 items, underflow! Adopt data from a sibling; update the parent If adopting won t work, delete node and merge with neighbor If the parent ends up with fewer than M/2 items, underflow! 2. If an internal node ends up with fewer than M/2 items, underflow! Adopt from a neighbor; update the parent If adoption won t work, merge with neighbor If the parent ends up with fewer than M/2 items, underflow! 4. If the root ends up with only one child, make the child the new root of the tree This reduces the height of the tree! 24 4

Thinking about B-Trees B-Tree insertion can cause (expensive) splitting and propagation B-Tree deletion can cause (cheap) adoption or (expensive) deletion, merging and propagation Propagation is rare if M and L are large (Why?) If M = L = 128, then a B-Tree of height 4 will store at least 0,000,000 items Tree Names You Might Encounter FYI: B-Trees with M =, L = x are called 2- trees Nodes can have 2 or keys B-Trees with M = 4, L = x are called 2--4 trees Nodes can have 2,, or 4 keys 2