4.9K views

Uploaded by byrusber

save

- B+ TREE TUTORIAL PPT
- DBMS-B+ and B trees
- AVLtrees
- File and Indexing
- mri
- B+ Trees
- B Trees Advanced)
- B+Tree
- Modern B Tree Techniques 1
- B+ Tree and Hashing
- Trees
- 06 - Trees
- B TREE TUTORIAL PPT
- BPlus Tree
- B-Trees
- Antipole IEEE Paper
- ExtentReport Review
- sqlite-version3
- b+ trees
- 10-techmap
- Coding Skills
- 2015-improg
- Tree Manager
- 18 Binary Tree Adt
- Bigdata_whitepaper_10!13!2009_public(How to Use Hadoop With Rdf)
- DA08
- Finals 2016 Solutions
- Dictionary
- Algorithms Lab Manual
- Lecture3 Notes
- Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
- Dispatches from Pluto: Lost and Found in the Mississippi Delta
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution
- Sapiens: A Brief History of Humankind
- Yes Please
- The Unwinding: An Inner History of the New America
- Grand Pursuit: The Story of Economic Genius
- This Changes Everything: Capitalism vs. The Climate
- A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
- The Emperor of All Maladies: A Biography of Cancer
- The Prize: The Epic Quest for Oil, Money & Power
- John Adams
- Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
- The World Is Flat 3.0: A Brief History of the Twenty-first Century
- Rise of ISIS: A Threat We Can't Ignore
- The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
- Smart People Should Build Things: How to Restore Our Culture of Achievement, Build a Path for Entrepreneurs, and Create New Jobs in America
- Team of Rivals: The Political Genius of Abraham Lincoln
- The New Confessions of an Economic Hit Man
- How To Win Friends and Influence People
- Angela's Ashes: A Memoir
- Steve Jobs
- Bad Feminist: Essays
- You Too Can Have a Body Like Mine: A Novel
- The Incarnations: A Novel
- The Light Between Oceans: A Novel
- Leaving Berlin: A Novel
- The Silver Linings Playbook: A Novel
- The Sympathizer: A Novel (Pulitzer Prize for Fiction)
- Extremely Loud and Incredibly Close: A Novel
- A Man Called Ove: A Novel
- The Master
- Bel Canto
- We Are Not Ourselves: A Novel
- The First Bad Man: A Novel
- The Rosie Project: A Novel
- The Blazing World: A Novel
- Brooklyn: A Novel
- The Flamethrowers: A Novel
- Life of Pi
- The Love Affairs of Nathaniel P.: A Novel
- The Bonfire of the Vanities: A Novel
- Lovers at the Chameleon Club, Paris 1932: A Novel
- The Perks of Being a Wallflower
- A Prayer for Owen Meany: A Novel
- The Cider House Rules
- Wolf Hall: A Novel
- The Art of Racing in the Rain: A Novel
- The Wallcreeper
- Interpreter of Maladies
- The Kitchen House: A Novel
- Beautiful Ruins: A Novel
- Good in Bed

You are on page 1of 28

B+-Trees (Part 1)

Slide 2

**Main and secondary memories
**

Secondary storage device is much, much slower than the main RAM Pages and blocks Internal, external sorting CPU operations Disk access: Disk-read(), disk-write(), much more expensive than the operation unit

Slide 3

Contents

Why B+ Tree? B+ Tree Introduction Searching and Insertion in B+ Tree

Slide 4

Motivation

**AVL tree with N nodes is an excellent data structure for searching, indexing, etc.
**

•

The Big-Oh analysis shows most operations finishes within O(logN) time

The theoretical conclusion works as long as the entire structure can fit into the main memory When the data size is too large and has to reside on disk, the performance of AVL tree may deteriorate rapidly

Slide 5

A Practical Example

**A 500-MIPS machine, with 7200 RPM hard disk
**

•

500 million instruction executions, and approximately 120 disk accesses each second (roughly, 500 000 faster!)

A database with 10,000,000 items, 256 bytes each (assume it doesn’t fit in memory) The machine is shared by 20 users Let’s calculate a typical searching time for 1 user

•

A successful search need log 10000000 = 24 disk access, around 4 sec. This is way too slow!!

We want to reduce the number of disk access to a very small constant

Slide 6

**From Binary to M-ary
**

**Idea: allow a node in a tree to have many children
**

•

Less disk access = less tree height = more branching

**As branching increases, the depth decreases An M-ary tree allows M-way branching
**

•

Each internal node has at most M children

**A complete M-ary tree has height that is roughly logMN instead of log2N
**

• •

if M = 20, then log20 220 < 5 Thus, we can speedup the search significantly

Slide 7

**M-ary Search Tree
**

Binary search tree has one key to decide which of the two branches to take M-ary search tree needs M-1 keys to decide which branch to take M-ary search tree should be balanced in some way too

•

We don’t want an M-ary search tree to degenerate to a linked list, or even a binary search tree

Slide 8

B+ Tree

**A B+-tree of order M (M>3) is an M-ary tree with the following properties:
**

1. 2. 3.

The data items are stored at leaves The root is either a leaf or has between two and M children Node:

s

s

The (internal) node (non-leaf) stores up to M-1 keys (redundant) to guide the searching; key i represents the smallest key in subtree i+1 All nodes (except the root) have between M/2 and M children A leaf has between L/2 and L data items, for some L (usually L

<< M, but we will assume M=L in most examples)

4.

Leaf:

s s

All leaves are at the same depth

Note there are vairous defintions of B-trees, but mostly in minor ways. The above definsion is one of the popular forms.

Slide 9

**Keys in Internal Nodes
**

Which keys are stored at the internal nodes? There are several ways to do it. Different books adopt different conventions. We will adopt the following convention:

•

key i in an internal node is the smallest key (redundant) in its i+1 subtree (i.e. right subtree of key i)

Even following this convention, there is no unique B+tree for the same set of records.

Slide 10

B+ Tree Example 1 (M=L=5)

Records are stored at the leaves (we only show the keys here) Since L=5, each leaf has between 3 and 5 data items Since M=5, each nonleaf nodes has between 3 to 5 children Requiring nodes to be half full guarantees that the B+ tree does not degenerate into a simple binary tree

Slide 11

B+ Tree Example 2 (M=L=4)

We can still talk about left and right child pointers E.g. the left child pointer of N is the same as the right child pointer of J We can also talk about the left subtree and right subtree of a key in internal nodes

Slide 12

**B+ Tree in Practical Usage
**

Each internal node/leaf is designed to fit into one I/O block of data. An I/O block usually can hold quite a lot of data. Hence, an internal node can keep a lot of keys, i.e., large M. This implies that the tree has only a few levels and only a few disk accesses can accomplish a search, insertion, or deletion. B+-tree is a popular structure used in commercial databases. To further speed up the search, the first one or two levels of the B+-tree are usually kept in main memory. The disadvantage of B+-tree is that most nodes will have less than M-1 keys most of the time. This could lead to severe space wastage. Thus, it is not a good dictionary structure for data in main memory. The textbook calls the tree B-tree instead of B+-tree. In some other textbooks, B-tree refers to the variant where the actual records are kept at internal nodes as well as the leaves. Such a scheme is not practical. Keeping actual records at the internal nodes will limit the number of keys stored there, and thus increasing the number of tree levels.

Slide 13

Searching Example

Suppose that we want to search for the key K. The path traversed is shown in bold.

Slide 14

Searching Algorithm

Let x be the input search key. Start the searching at the root If we encounter an internal node v, search (linear search or binary search) for x among the keys stored at v

• • •

If x < Kmin at v, follow the left child pointer of Kmin If Ki ≤ x < Ki+1 for two consecutive keys Ki and Ki+1 at v, follow the left child pointer of Ki+1 If x ≥ Kmax at v, follow the right child pointer of Kmax

If we encounter a leaf v, we search (linear search or binary search) for x among the keys stored at v. If found, we return the entire record; otherwise, report not found.

Slide 15

Insertion Procedure

we want to insert a key K Search for the key K using the search procedure This leads to a leaf x Insert K into x

• •

If x is not full, trivial, If so, troubles, need splitting to maintain the properties of B+ tree (instead of rotations in AVL trees)

Slide 16

**Insertion into a Leaf
**

A: If leaf x contains < L keys, then insert K into x (at the correct position in node x) D: If x is already full (i.e. containing L keys). Split x

• • •

Cut x off from its parent Insert K into x, pretending x has space for K. Now x has L+1 keys. After inserting K, split x into 2 new leaves xL and xR, with xL containing the (L+1)/2 smallest keys, and xR containing the remaining (L+1)/2 keys. Let J be the minimum key in xR Make a copy of J to be the parent of xL and xR, and insert the copy together with its child pointers into the old parent of x.

•

Slide 17

Inserting into a Non-full Leaf (L=3)

Slide 18

Splitting a Leaf: Inserting T

Slide 19

Splitting Example 1

Slide 20

Two disk accesses to write the two leaves, one disk access to update the parent q For L=32, two leaves with 16 and 17 items are created. We can perform 15 more insertions without another split

q

Slide 21

Splitting Example 2

Slide 22

Cont’d

=> Need to split the internal node

Slide 23

**E: Splitting an Internal Node
**

To insert a key K into a full internal node x: Cut x off from its parent Insert K as usual by pretending there is space

•

Now x has M keys! Not M-1 keys.

**Split x into 3 new internal nodes xLand xR, and xparent!
**

• • •

xL containing the ( M/2 - 1 ) smallest keys, and xR containing the M/2 largest keys. Note that the (M/2)th key J is a new node, not placed in xL or xR

Make J the parent node of xL and xR, and insert J together with its child pointers into the old parent of x.

Slide 24

Example: Splitting Internal Node (M=4)

3+1 = 4, and 4 is split into 1, 1 and 2! So D J L N is into D and J and L N

Slide 25

Cont’d

Slide 26

Termination

Splitting will continue as long as we encounter full internal nodes If the split internal node x does not have a parent (i.e. x is a root), then create a new root containing the key J and its two children

Slide 27

**Summary of B+ Tree of order M and of leaf size L
**

• • • •

Each (internal) node has at most M children (M-1 keys) Each (internal node), except the root, has between M/2-1 and M-1 keys Each leaf has at between L/2 and L keys and corresponding data items The root is either a leaf or 2 to M children

We assume M=L in most examples.

Slide 28

Roadmap of insertion

Main conern: leaf and node might be full!

**insert a key K Search for the key K and get to a leaf x Insert K into x
**

• •

**If x is not full, trivial, If full, troubles ,
**

•

need splitting to maintain the properties of B+ tree (instead of rotations in AVL trees)

**A: Trivial (leaf is not full) B: Leaf is full
**

•

C: Split a leaf,

D: trivial (node is not full) • E: node is full Split a node

•

- B+ TREE TUTORIAL PPTUploaded byharshilsurti
- DBMS-B+ and B treesUploaded byMageshwari Dharaneeswaran
- AVLtreesUploaded byNaveen Raj
- File and IndexingUploaded byMuhammad Ali
- mriUploaded bySakshi Kathuria
- B+ TreesUploaded bybyrusber
- B Trees Advanced)Uploaded byapi-3801329
- B+TreeUploaded byapi-3747983
- Modern B Tree Techniques 1Uploaded byHiroki Kumazaki
- B+ Tree and HashingUploaded byaismahesh
- TreesUploaded byvijayaazeem
- 06 - TreesUploaded byAmir Afzal
- B TREE TUTORIAL PPTUploaded byharshilsurti
- BPlus TreeUploaded byPuneet Choudhary
- B-TreesUploaded byGurpreet Kaur
- Antipole IEEE PaperUploaded bybhoslemanoj
- ExtentReport ReviewUploaded byshaikameermalik
- sqlite-version3Uploaded bycrazydman
- b+ treesUploaded byAnandaKrishna Sridhar
- 10-techmapUploaded byBonnie Thompson
- Coding SkillsUploaded byMaddy137
- 2015-improgUploaded byajitkarthik
- Tree ManagerUploaded bysudhascareer
- 18 Binary Tree AdtUploaded byVongsagon Boonsawat
- Bigdata_whitepaper_10!13!2009_public(How to Use Hadoop With Rdf)Uploaded byMohamed Fouad
- DA08Uploaded byAnindo Chatterjee
- Finals 2016 SolutionsUploaded bySaumo Pal
- DictionaryUploaded bychaturaka
- Algorithms Lab ManualUploaded byakilrsdi
- Lecture3 NotesUploaded bynguyen293