1 / 11

B + Trees

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 Nodes contain Key values and node pointers Leaf Nodes contain Key, Record-Pointer pairs. B + Trees.

jennis
Download Presentation

B + Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 <P1, K1, P2, K2, ..., Pq-1, Kq-1, Pq > , where q <= p , each Pi  is a tree pointer • Within each internal node, K1 < K2 < ... < Kq-1 • For all values of X in the subtree pointed at by Pi , we have Ki-1 < X < Ki  for 1 < i < q , X < Ki for i=q, and Ki-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. B+ Trees • The structure of leaf nodes in a B+ tree of order p: • Each leaf node is of the form < <K1,Pr1>,  <K2,Pr2>,  ..., <Kq-1,Prq-1>,  Pnext > , where q <= p , each Pri  is a data pointer that points to a record or block of records • Within each internal node, K1 < K2 < ... < Kq-1 • Each leaf node, has at least (p/2) values • All leaf nodes are at the same level • The Pnext pointer points to the next leaf node in the tree • This give efficient sequential access to data

  6. B+ Trees

  7. B+ Trees • 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 <= entry's key value < K i+1;         insert (Pi, entry, newchildentry);         if newchildentry is null, return;         else,             if N has space,                 put *newchildentry on it, set newchildentry to null, return;             else,                 split N:                 first d key values and d + 1 nodepointers stay,                 last d keys and d + 1 pointers move to new node, N2:                 newchildentry = &(<smallest key value on N2, pointer to N2>);                 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 = &(<smallest key value on L2, pointer to L2>);                 set sibling pointers in L and L2;                 return; endproc

  9. 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

More Related