Record lookup( x )
{
n = root node; // Start at the root
/* ========================================
Traverse internal nodes to reach a leaf
======================================== */
while ( n ≠ leaf node )
{
n is indexed using component i;
if ( x.compi < n.key )
n = n.left;
else
n = n.right;
}
/* ============================
We have reached a leaf node
============================ */
if ( x is found in n (leaf node) )
{
return Record for x
}
else
{
return No Found;
}
}
|
Example: lookup age = 35 and salary = 500K
|
insert ( Record x )
{
Use the search key in x to find:
the leaf node L that will hold x
if ( L has space )
{
insert record x in (block) L;
}
else
{
Choose a component key value K that:
divides L into 2 halves: L1 and L2;
Move all records with key < K into L1;
Move all records with key >= K into L2;
Replace L by an internal node with key K;
K,left = L1;
K.right = L2;
}
}
|
|
|
|
Search Algorithm:
|
Example:
|
|
|
Search Algorithm:
|
Example:
|
|
|