Documente Academic
Documente Profesional
Documente Cultură
Example of an OS-tree
Selection
Implementation trick: Use a sentinel
(dummy record) for NIL such that size[NIL] = 0.
M
M
99
CC
55
PP
33
AA
11
FF
33
NN
11
DD
11
OS-SELECT(x, i)
QQ
11
HH
11
Example
M
M
99
CC
55
PP
33
FF
33
DD
11
OS-Rank(T,x)
i=5
k=6
AA
11
OS-SELECT(root, 5)
i=5
k=2
key
key
size
size
i=3
k=2
HH
11
NN
11
i=1
k=1
QQ
11
Assume x already found, and the path from the root is known
r size[left[x]]+1
Recall that if left[x]] is NIL then its size=0
yx
While ( y root(T)) {
do if y is the right child of parent[y]
then r += size[left[ parent[ y ]]] +1
y parent[ y ]
}
Return r
Example of insertion
INSERT(K)
M
M
10
910
9
CC
56
6
5
PP
33
AA
11
FF
34
4
3
DD
11
NN
11
QQ
11
HH
12
2
1
KK
11
Handling rebalancing
Data-structure augmentation
Example:
EE
16
16
CC
11
11
7
CC
16
16
4
EE
88
7
3