Presentation is loading. Please wait.

Presentation is loading. Please wait.

B + Trees Dale-Marie Wilson, Ph.D.. B + Trees Search Tree Used to guide search for a record, given the value of one of its fields Two types of Nodes Internal.

Similar presentations


Presentation on theme: "B + Trees Dale-Marie Wilson, Ph.D.. B + Trees Search Tree Used to guide search for a record, given the value of one of its fields Two types of Nodes Internal."— Presentation transcript:

1 B + Trees Dale-Marie Wilson, Ph.D.

2 B + Trees Search Tree Used to guide search for a record, given the value of one of its fields Two types of Nodes Internal Nodes contain Key values and node pointers Leaf Nodes contain Key, Record-Pointer pairs

3 B + Trees The structure of internal nodes in a B + tree of order p: Each internal node is of the form, where q <= p, each P i is a tree pointer Within each internal node, K 1 < K 2 <... < K q-1 For all values of X in the subtree pointed at by P i, we have K i-1 < X < K i for 1 < i < q, X < K i for i=q, and K i-1 < X for i=q Each internal node has at most p tree pointers Each internal node, except the root, has at least (p/2) tree pointers. The root node has at least two tree pointers if it is an internal node. An internal node with q pointers, q <= p, has q-1 search field values.

4 B + Trees

5 The structure of leaf nodes in a B + tree of order p: Each leaf node is of the form,,...,, P next >, where q <= p, each Pr i is a data pointer that points to a record or block of records Within each internal node, K 1 < K 2 <... < K q-1 Each leaf node, has at least (p/2) values All leaf nodes are at the same level The P next pointer points to the next leaf node in the tree This give efficient sequential access to data

6 B + Trees

7 Insertion example for B + Tree: When you insert into a leaf node that is full, you split and pass the middle value up to the parent When you insert into a full root, the root splits and a new root is created with the middle value from the child nodes Otherwise, values are inserted into openings at the lowest level

8 B + Trees proc insert (nodepointer, entry, newchildentry) if *nodepointer is a non-leaf node, say N, find i such that Ki ); if N is the root, create new node with (pointer to N, *newchildentry); make the tree's root-node pointer point to the new node; return; if *nodepointer is a leaf node, say L, if L has space, put entry on it, set new childentry to null and return; else, split L: first d entries stay, rest move to brand new node L2; newchildentry = &( ); set sibling pointers in L and L2; return; endproc

9

10

11 In-class Example: Write the B+ Tree (p = 4) for the following values that are inserted into the B Tree in the order below. 17, 2, 98, 23, 27, 34, 0, 44, 68, 19, 72, 10, 5, 55, 3


Download ppt "B + Trees Dale-Marie Wilson, Ph.D.. B + Trees Search Tree Used to guide search for a record, given the value of one of its fields Two types of Nodes Internal."

Similar presentations


Ads by Google