B+ Tree Example


The size of DATA below is 1344 bytes. Assuming 4096 bytes per page, we would only get 3 structs per page. This is essentially a 2-3-4 tree.

struct DATA
{
  int ID; // the key
  char Name[32];    
  struct 
  {
    double x;
    double y;
    double z;
  } Position;
  double NFA[128];
  int DFA[64];
};
As a B+ tree, we'd get 511 keys per page, assuming 8-byte pointers. (4088 / 8 = 511).
Internal nodes contain only keys and pointers to nodes. Leaf nodes contain pointers to data.

This example shows a B+ tree of order 4 (order is same as branching factor). In other words, a 2-3-4 tree.

Adding 3588 to the empty tree:

Adding 2820:

Adding 4606: (The root node is now full.)

Adding a new node (any value) now causes the root to split:

Adding 1900:

Adding 1558:

Adding 8280:

Adding 1067 causes the leaf to split:

Adding 1067:

Adding 2250:

Adding 7284 causes the right-most leaf to split (root is now full):

Adding 7284:

Adding any new node causes the root to split:

Adding 7809 causes the right-most leaf to become full:

Adding 7660 causes the right-most node to split:

Adding 6816 causes an internal node to split:

Adding 6816:

Some implementations link the leaves together for easy in-order traversal. (Range searches)