Top Banner
B-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In theory if there is just too much data to store in memory use for EXTERNAL searching, real data is stored in secondary memory build a structure to point you in the right direction of where that data is stored o actual storage could be hard drives, some permanent storage, etc… as many B-Tree nodes are stored in memory as possible to speed up the search data (leaves) are stored elsewhere, off site, requiring access (hard drive, etc…) B-Tree Big Picture 1
51

faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Jan 19, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

B-TreesLook into old 341 PPT notes of B-Trees, The N/L portion on these notes need work

In theory if there is just too much data to store in memory use for EXTERNAL searching, real data is stored in secondary memory build a structure to point you in the right direction of where that data is stored

o actual storage could be hard drives, some permanent storage, etc… as many B-Tree nodes are stored in memory as possible to speed up the

search data (leaves) are stored elsewhere, off site, requiring access (hard drive, etc…)

B-Tree Big Picture

also called an M-way treeo M is the number of pointers (or links) OUT of each node in the tree

Data is stored in the LEAVES

1

Page 2: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

o Leaves can store multiple data valueso leaves are ALL at the same level

A B-tree is kept balanced by requiring that all leaf nodes be at the same depth The tree structure itself is built using the data given

o data does not have to be uniform

2

Page 3: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Definition (Rules) of a B-TreeA B-Tree of order M is an M-Way tree with the following constraints

1. The root is either a leaf or has between 2 and M subtrees2. All interior node (except maybe the root) have between ⌈ M /2 ⌉ and M subtrees

(i.e. each interior node is at least “half full”)3. All leaves are at the same level. 4. A data leaf must store between ⌈ L/2 ⌉ and L data elements, where L is a fixed

constant >= 1 (i.e. each leaf is at least “half full”, except when the tree has fewer than L/2 elements)

Complete B-Tree

Notice the 2 “18”s. One is a direction node, the other is real data.Also notice, if the match, placed to the right.

3

Page 4: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Disk Access assume each node is a block of data ON a disk accessing (and getting to) that spot takes time accessing the data WITHIN that spot takes time

o but linear, so fast storing the KEYS of the tree as much as possible in memory will speed things

up substantially

Applications for B-Trees need to keep this in mind!! very simple way of finding values single and range of values!!

o L or (L – M) minimizes time consuming jumps in disk since most heaped together in blocks

4

Page 5: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Constructing a B-Tree (setup) you at LEAST need to know how many total pieces of data you need to

handleo or have an estimate!

so we can determine an appropriate M, h and Lo M = split up of data per node, or children per node

also called Max Degreeo h = height of the tree, how many nodes must be visited before

determining the leaf location of data might find out after all is said and done as M increases, h decreases

M does matter (31 nodes each)M = 3

29, 7, 17, 22, 6, 24, 10, 25, 16, 19, 27, 2, 26, 4, 8, 1, 31, 3, 30, 23, 9, 15, 21, 5, 14, 13, 18, 12, 11M = 7

L = number of values a leaf can hold all data will be handled in the LEAVES of the B-Tree all data will be ORGANIZED by the structure of the B-Tree

5

Page 6: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Constructing a B-Tree (Algorithm) data will come in random order based on M, fill root node with first M-1 pieces of data, sorted

What does “M” mean?M = 3 M = 7

How many pieces of data?How many pieces of data?

once root is filled, and one more is ADDED to overload node, pick middle value of node, and “split” to make NEW rooto middle value (index) WE use will be floor((M – 1)/ 2)

M = 5, then index 2o defining the MIDDLE value is not always consistent in every algorithm

Promoting the middleM = 5 M = 4

Many people will get this wrong!! (On the test!!)

6

Page 7: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Constructing a B-Tree, M = 5Initial data

1 12 8 2 25 5 14 28 17 7 52 16 48 68 3 26 29 53 55 45

create base root node (remembering M , or M-1)

adding 25, we know a split should happen

Think of it as 25 WAS added, the middle was 8. It was promoted.Notice that each node has a lot more room to fill.Won’t have to split again, until someone fills up.added 5

notice where 5 was added!! Notice that data is only added to the bottom (leafs)added 14 and 28

why do you think I stopped here?

7

Page 8: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

added 17

Again, think of it as 17 was added, it was the middle of an overloaded node, so promote it, and splitadded 7, 52, 16, 48

added 68

48 was middle of overloaded node, promote it, and splitadded 3

3 was middle of overloaded node, promote it, and splitadded 26, 29, 53, 55

added 458

Page 9: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Now what just happened?

Revisiting promotion Node is MAXED out

o 1 over actuallyo something needs to give

arrange values in order pick middle while promoting middle, have middle connect to both side of the original node

Promotion ProcedureOverloaded Node (M = 5)

Split, Promote and Point

You try: 5, 3, 21, 9, 1, 13, 2, 7, 10, 12, 4, 8 with a B-Tree order (M) of 4, so middle index = 1. Answer on next page.

Instructor example answer

9

Page 10: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

https://www.youtube.com/watch?v=1Xcha3FXt5Y

Interior Nodes and the M/2 – M subtrees Rule INTERIOR NODE ONLY

o not root or leaf While building, promoting, deleting, etc… to check to see if your B-tree is

(probably) right, check that the Take a look through our answers and notice every interior node is between

⌈ M /2 ⌉ and M subtrees A root (at least) could be 1 key even if M = 5 since we only promote one key

value

Rules of a B-Tree1. The root is either a leaf or has between 2 and M subtrees2. All interior node (except maybe the root) have between ⌈ M /2 ⌉ and M subtrees

(i.e. each interior node is at least “half full”)3. All leaves are at the same level. A data leaf must store between ⌈ L/2 ⌉ and L data elements, where L is a fixed constant >= 1 (i.e. each leaf is at least “half full”, except when the tree has fewer than L/2 elements)

1. Using the rules above, which of the following are legal B-trees for when M = 5? For those that are not legal, give one or two sentence very clearly explaining what property was violated.

(more next page)2. Draw the B-tree that will be created after inserting the following elements (in

this order) A,B,C,D,G,H,K,M,R,W,Z. M = 4

10

Page 11: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

3. Draw the B-tree that will be created after inserting the following elements (in this order) R,Y,F,X,A,M,C,D,E,T,H,V,L,W,G. M = 5 Answerb:

Inserting data using a B-Tree remember, the data is not stored in the B-Tree itself but in the “leaves” which are certain storage areas

o L IS NOT EQUAL TO M!!o meaning M does not dictate L o although they are related

the B-Tree nodes directs us on where the data should be storedo called keys!!

if the leaf has room (<= L elements)o insert X o write the leaf back to the disk

if the is leaf fullo split it into two leaves, each with half of elementso insert X into the appropriate new leaf and write new leaves back to the

disko update the keys in the parento if the parent node is already full, split it in the same manner

splits may propagate all the way to the root, in which case, the root is split (this is how the tree grows in height)

splitting allows up to “update” the structure if we need to

11

Page 12: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Inserting values into a B-TreeB-Tree with M = 4 and L = 3

inserted 33

notice 33 is ordered in the leaf

12

Page 13: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

inserting 35

This item also belongs in the 3rd leaf of the 2nd subtree. However, that leaf is full.Split the leaf in two and update the parent.

13

Page 14: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

inserting 21 (part 1 of 3)

since leaf is too full, split, and add to root (part 2 of 4)

14

Page 15: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

since immediate root is too full, split again, add to root (part 3 of 4)

but now the highest root is also too big!! Split and promote new node as root (part 4 of 4)

15

Page 16: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

In reality,1. How many new links were added? (ballpark)2. How many links changed targets? (ballpark)

Counting the repercussions (links)Before After

Try these using the B-Tree Structure below:

B-Tree General Exercise

1. What are the values of M and L? 2. What is the time cost (in terms of number of disk access) needed to access any information (data items). 3. Add the following in order into the B-Tree: (All changes are permanent)(a) Inserting RECORD DATA valued 1. (b) Inserting RECORD DATA valued 33. (c) Inserting RECORD DATA valued 17.

16

Page 17: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Searching for a value in a B-Tree different than BST since ALL real data is in the leaves

o since the leaf can hold multiple items, might need to scan to findo or sort while inserting??

all search paths have same length: ⌈ log n ⌉o then we reach the leaves with actual data (costs more time)o search through list of data at that leaf

use KEYS (B-Tree Nodes) to point us to the real data (leaves)o keys and data do NOT have to be the same!! o use the same values just to represent and teach

while searching through the entire structure, only 3 conditionso if node == NULL, not found, return nullo if node == leaf, search list of values, return null if list exhaustedo else if node is an interior node, use keys to find which subtree to move

to next

Searching by Key to Find the Data

What would it look like to get a range of values? (L to M)

17

Page 18: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

But why a B-Tree? (Over a BST) both have pros and cons

o height – advantage B-Tree (example could be flatter with a greater M)o comparisons – advantage BST (if M is large, could be worse for B-Tree)o memory data storage – advantage B-Tree, since stored off site

Comparing Data StructuresBST B-Tree

31 notes in a BST31 nodes in a B-Tree, M = 5

is it worth it to let M balloon?o number of nodes visited does decrease drasticallyo but the computation and comparison increases

there is a trade off on if it takes longer to go down a VERY LONG BST over a B-Tree traversal pointing you into the right spot a little faster, and disk access

18

Page 19: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

The battle rages (both with 31 nodes)B-Tree (M = 7)

(pretend the LAST row is data)BST

Answer for each:How many comparisons to find a value, smallest to largest?Links to build?Nodes to build?Delete a node costs? (one key in a B-Tree)Pick to random values that are in both trees, how long did it take to find each?

19

Page 20: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Maximum number of keys watch for the rules of a B-Tree (above) t = (M) degree, h = height (2t)h+1 -1

Max number of nodes explained

20

Page 21: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Designing and Building a B-Tree in Real Life find out how large our data is first, to make a realistic decisions on M, h, etc… B-trees are often used when there is too much data to fit in memory

o each node and leaf access costs one disk access!! when designing a B-Tree (choosing the values of M and L) consider

o the size of the data stored in the leaveso the size of the keys and pointers stored in the interior nodeso the size of a disk block

B-Tree Design Terms

21

Page 22: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Worse versus Best case in B-Tree scenarios remember with a given “M”, we could have a

o tall tree = M/2 (-1) amount of keys in each nodeo wide tree = M (-1) amount of keys in each node

tall versus wide B-Tree visually

Tall

worse case

M/2 keys

Wid

e

best case M keys

How any disk access if the entire tree was stored on the HD for tall and wide?Which one would be faster then?

22

Page 23: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Breaking down a diskblock diskblock is allocated a specific size in each B-Tree problem there will be some diskblocks used for keys and some for records keys

o remember there is one more pointer than datao may not be able to fit perfectly

half a pointer or key will have to be placed elsewhere records

o MUCH larger than keys since it contains the key and real data

How the diskblock works for keys and recordsIn Theory In reality

(in both cases, the diskblock(s) does not have much in it)

Given the same diskblock allocation size, the # of keys will be ____ than the # of records? ( <, >, == are your possible answers)

23

Page 24: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Solving B-Tree Problems In these problems, you are given details such as

o number of records that this tree needs to be able direct and to hold (minimally)

called “N”o data size details

keys diskblocks records branches

But you have to solve foro M, best fit given diskblock, key and branch sizeso L, given diskblock and record size

easyo Performance - How many disk access if ALL diskblocks were M/2

M/2 minimal M admissible for interior nodes

B-Tree Problem Ex. 1Suppose our B-Tree stores 25,000 student records which contain name, address, etc. and other data totaling 1024 bytes. Further assume that the key to each student record (ssn-ish??) is 8 bytes long. Assume also that a pointer (really a disk block number, not a memory address) requires 4 bytes And finally, assume that our disk block is 4096 bytes

1. Collect data from question

N 25,000 (minimally) diskblock 4096bkey 8b record size 1024bpointer 4b

24

Page 25: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

2. Solve for Mi (initial) and Mf (final)

Mathematically Visually

4096b = (M-1)8b + M4b4096b = M8b - 8b + M4b4096b = M12b – 8b4104b = M12b342 = Mi

since we cannot have a fraction of an “M”, need to floor the result of Mi

⌊342 ⌋ = Mf

342 = Mf

all keys all pointershence why = (M-1)8b + M4b

FLOOR since we cannot add to the space. We are given a limited amount of room.

3. Solve for L

Mathematically Visually

L = ⌊Block ¿¿ record ¿ ⌋ ¿¿

L = 4096/1024L = 4

FLOOR since we cannot add to the space. We are given a limited amount of room.25

Page 26: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

4. Determine worst performance of tree with given N (# of disk accesses)

Mathematically Visually

Mmin = M/2 for all interior nodes

Mmin = 342/2Mmin = 171

Disk access = 2 since we needed 25,000 (or N)

WORST can also be done by: ⌈ log171 (25000 ) ⌉ = 2

Notice root (which could be 1) is not included

BTW – Best case performance is done by: ⌈ log342 (25000 ) ⌉ = 2

CEILING since we cannot have a half/quarter/etc… of a disk access!

Using a B-Tree, we want to store and process information concerning the driving records for citizens in the state of Maryland. We assume the following:

we have 300,000,000 items, each key is 8 bytes (ID number), a record is 256 bytes, one disk block holds 8,192 bytes, and a pointer to each block is of size 4 bytes.

(a) What are the values of M and L in this case? (b) What is the number of leaf nodes in the best and worst cases? (c) What is the height of the B-Tree in the worst and best case? (Root in memory)(d) What is the number of disk accesses needed to get any information? Answerb:

26

Page 27: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Deleting from a B-Tree (is complicated) data leaf deletion (not covered)

o concerned with L non-data node deletion (shown)

o concerned with Mo deleted key can be a leaf or internal

leaf , delete, watch for B-Tree compliant violations parent , promote closest child, then go to child location, and check

for B-Tree violations

Reminder of key versus nodeNode Key(s)

o eventually, all deletions will be a leaf why leave, no M to M/2 rule for leaves!! but all leaves MUST be on the same level!!

o this can be recursive in some cases!! since the parent might have changed, and no longer M to M/2

complianto underflow

no keys left in a node when target key deleted

What is underflow?

27

Page 28: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Case 1 – Deleting a Key that is a leaf, no underflow simplest of the deletions just remember that a leaf does NOT have to follow the M to M/2 rule when the target key is deleted, there is at least other keys still left in the node

Deleting non-data LEAF nodes in a B-TreeB-Tree example

5, 3, 21, 9, 1, 13, 2, 7, 10, 12, 4, 8 (M = 3)Deleting 4 (no issues, but watch the process)(search for 4 first!)

Again, leaves do not need to follow M to M/2 rule

Case 2 – Deleting a non-leaf key & avoiding underflow28

Page 29: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

deletion of key happens as normal but we need to promote the highest left child nodes value

Deleting non-leaf key Example #1Original B-Tree

Find target key 9 and delete

Promote left node’s highest value key.

Finished

Deleting non-leaf key Example #1What if 13 was deleted??

29

Page 30: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Case 3 – Deleting a Key that is a leaf, underflow, steal from bigger sibling

almost looks like a rotation there is a demotion of the parent, and promotion of the bigger sibling’s key

value that is closest to the parent’s original value

Delete and rotateDelete target key 1

Recognize underflow, and that all leave nodes need to be at the same level.

Demote Parent into deleted location

Promote closest sibling alue to parent

What would happen if 21 was deleted?? Answerb:

30

Page 31: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Case 4 – Deleting a Deleting a Key that is a leaf, underflow, merge sibling and parent

overall, an internal node is about to get demoted need to replace a leaf

o so all are still at the same level

Delete, Merge and DemoteOriginal B-Tree

Delete 21

Recognize that stealing from a sibling is not possible. Merge closest sibling and parent. Demote newly merged keys to deletion location.

31

Page 32: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

In deletion, it’s always the leaves… really notice that in each case the leaves are really the ones that get “deleted” this can have a conflict if the leaf node ends up empty

o in that case we use the other cases to help us solve this

When one Case is just not enoughOriginal B-Tree

Find target key 9 and delete

Promote left node’s highest value key key.

But wait!! Now we have a Case 3!!

Steal from bigger sibling

Finished

32

Page 33: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

AnswersLegit B-Trees

(i): Not legal since the height is not balanced. More specifically, both the node with “BD” and “KS” are at the same level but “BD” is a leaf and “KS” is not.(ii): This is legal. Remember, that the root can have just a single key.(iii): This is illegal. “D” has to follow the M/2 rule for leafNodes(iv): This is illegal.(v): This is illegal. There is no pointer from GL.

Building a B-Tree Exercise #2

https://www.youtube.com/watch?v=DJi2TNjiHnM&list=PLC7fNkE1QplYl6peBRlcvtkUcbOV3Izbi&index=4

Building a B-Tree Exercise #3

https://www.youtube.com/watch?v=dfSmCuCuDaE&index=1&list=PLC7fNkE1QplYl6peBRlcvtkUcbOV3Izbi

33

Page 34: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

General B-Tree Exercises

1. M and L are 52. 3 disk access

Inserting 1

Inserting 33

Inserting 17

34

Page 35: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Designing a B-Treea. Solution: M=683, L=32.

floor( 8192/256) = 32 = L

( 4 bytes (M) + ( 8 bytes(M-1)) <= 8192 bytes( 4 bytes (M) + ( 8 bytes(M) – 8 bytes )) <= 8192 bytes12 bytes M <= 8200 bytesM <= floor(683.3333)M <= 683

(b) What is the number of record leaf nodes in the best and worst cases?b. Solution: 9,375,000 leaves in the best case and 18,750,00 in the worst case

(300,000,000 * 256)/8192 (Max M)300,000,000 /32 = 9375000 leave in the best scenario

(300,000,000 * 256)/(8192/2) (Max M/2 for minimum)300,000,000 /16 = 18750000 leave in the best scenario

(c) What is the height of the B-Tree in the worst case?

c. Solution: Height = 3 (or 4 if we count the root – root is usually in memory).

height = ceiling(log341(300,000,000)) = 4 but 3 since 1 is in rootheight = ceiling(log683(300,000,000)) = 2.99 so 3 but 2 since 1 is in root

(log 300000000) / (log 683)(d) What is the number of disk accesses needed to get any information?

d. Solution: 4 disk access.

4 disk access = (height + 1 for the root)

35

Page 36: faculty.cse.tamu.edufaculty.cse.tamu.edu/.../DataStructures/B-TreesNotes.docx · Web viewB-Trees Look into old 341 PPT notes of B-Trees, The N/L portion on these notes need work In

Deleting 21 from the B-tree (Case 2)

SourcesIn Generalcecs.wright.edu/~tkprasad/courses/cs707/L04-X-B-Trees.ppthttp://www.cs.wustl.edu/~sg/CSE241_SP06/btree-practice-probs.pdfhttp://www.geeksforgeeks.org/b-tree-set-1-introduction-2/

Insertionhttp://www.geeksforgeeks.org/b-tree-set-1-insert-2/

Animationhttp://www.cs.usfca.edu/~galles/visualization/BTree.html

Deletinghttp://www.wou.edu/~broegb/IS320/BTree.PPThttps://www.youtube.com/watch?v=fKubKYzwDl0http://webdocs.cs.ualberta.ca/~holte/T26/del-b-tree.htmlhttp://www.geeksforgeeks.org/b-tree-set-3delete/

BulkloadingDennis Frey and Tom Anastasio CMSC 341 slides

36