Upload
maskply
View
228
Download
0
Embed Size (px)
Citation preview
8/13/2019 btree.doc
1/9
AB-treeTis a rooted tree (whose root is root[T]) having the following properties:
1. Every node xhas the following fields:
a. n[x], the number of eys !urrently stored in node x,
b. the n[x] eys themselves, stored in non de!reasing order, so that key"[x]
# key1[x] # $$$ # keyn[x]%1[x],
!. leaf [x], a boolean value that is &'E if xis a leaf and A*+E if xis
an internal node.
. Ea!h internal nodexalso !ontains n[x]- 1 pointers c"[x], c1[x], ..., cn[x][x] to its
!hildren. *eaf nodes have no !hildren, so their cifields are undefined.
. &he eys keyi[x] separate the ranges of eys stored in ea!h subtree: if kiis any
ey stored in the subtree with root ci[x], then
k"# key"[x] # k1# key1[x] #$$$ # keyn[x]%1[x] # kn[x].
/. All leaves have the same depth, whi!h is the tree0s height h.
. &here are lower and upper bounds on the number of eys a node !an !ontain.&hese bounds !an be e2pressed in terms of a fi2ed integer t3 !alled the
minimum degreeof the 4%tree:
a. Every node other than the root must have at least t% 1 eys. Every
internal node other than the root thus has at least t!hildren. 5f the tree
is nonempty, the root must have at least one ey.
b. Every node !an !ontain at most t% 1 eys. &herefore, an internal node
!an have at most t!hildren. 6e say that a node isfullif it !ontains
e2a!tly t% 1 eys.
8/13/2019 btree.doc
2/9
4%&ree%+ear!h(2, )
i keyi[x] do i
8/13/2019 btree.doc
3/9
8/13/2019 btree.doc
4/9
8/13/2019 btree.doc
5/9
ow before inserting, the root is splinted:
inally after the last slinting:
8 =,,6
&
;
8 = *,@, ',+ >,6
, < &
;
8/13/2019 btree.doc
6/9
. +how all legal 4%trees of minimum degree that represent 1, , , /, B.
solution:
we now that every node % e2!ept the root % must have at list t%1 eys, that
and at most t%1 eys. Also remember that the leaves stay in the same depth:
1.
.
.
/.
. 6hy don0t we allow a minimum degree of tC 1D
Solution:
6e get a 4%tree nodes with no eys.
1 ,/,
1, /,
/
1,,
/
1
8/13/2019 btree.doc
7/9
/. E2plain how to find the ma2imum ey stored in a 4%tree and how to find the
prede!essor of a given ey stored in a 4%tree.
Solution:
inding the ma2imum in a 4%tree is ?uite similar to finding a ma2imum in a binary
sear!h tree we need to find the right most leaf for the given root, and return the last
ey.
ind%@a2imum(2) FF assumption: the tree is not emptyif leaf[2]
retrun (eyn[2]%1[2])
else
return ind%@a2imum(8n[2][2])
8omple2ity: in the height of tree 9(logtn).
inding the prede!essor of eyi[2] (given 2 and i ) is a!!ording to the following rools:
1. if the 2 is not a leaf return the ma2imum of 8i[2] (every ey in this subtree
apply keyi%1[x] # k# keyi[x] ,if keyi%1[x] e2ist)
. otherwise (it is a leaf) if iG" we return eyi%1[2].
if the above !onditions are not satisfied, we loo for the first prede!essor node
y, that its pointer 8i[y] is also the prede!essor of 2 and iG" we return ey i%1[y], if su!h node y is not e2ist, nil is returned.
ote: we add another field p for ea!h node that points to it0s father.
8/13/2019 btree.doc
8/9
Hrede!essor(2,i ) FF we want the prede!essor to of ey i[2]if not leaf[2]
return ind%@a2imum(8i[2])
else if iG"
return eyi%1[2]
else
found
8/13/2019 btree.doc
9/9