ScanGate document
Trang 1
OPTIMIZATION FOR ONE-DIMENSIONNAL BINARY SEARCH TREES
Do Duc Giao and A Min TIOA Institute of Applied Computer Science and Information Systems, University of Vienna (Austria)
1, Abst
This paper introduces axiom schemes for binary search trees Inference rules for binary search trees are specified A prove of a theorem which shows that cach tree can be uniquely transformed into an optimal tree by using the axiom schemes and the rules of inferences are introduced in this paper
2 Introduction
The notion of a search tree plays an important role in computor science, especially in the theory of data Istructures For that reason we can find many papers concerned with the theory of search trees in the literature, We noticed that, above all, questions of the optimal construction and inductive generation of seurch trees and studied, where equivalent transformations of search trees are offen used |1,2,3,4,5,6)
In this paper we will give the fundamentals of such theory and optimization problem for the set of one-dimensional binary search trees wilh infomations in their Te:
3 One-dimerzionnal binary search trees
Let D and be the set of documents and the set of the nonegative integers Let the symbols /</>/,/ cot be in the set Du K, tis the empty tree We denote D* ; = Du {t} Now we define the set TREE of all one- dimensionnal binary search trees with informations in leafs as follows + Definition |
2 1f Ty and Tp are trees and k € K, then k,TỊ/T2>or we
K is the set of keys of the set TREE of all one-dimensionnal binary search trees informations
in theri leafs (Definition 1) We define the RESULT (T, () of searching in the tree T € TREE with the key fe K by
Delinition 2
1, RESULT (d, @): = d for every de Dt
49
Trang 22 RESULT (K<T},T2>@): = RESULT (Ty, /) if @sk
Ki SULT Á<T4/T2> Ê): = RESL LT (Tạ, (if Ê>k
The base of Uw following investigation is the dei nition of equivalcive of trees of TREE In the sense of retrieval theory another equivalent relation for trees is relevant
Definition 3
Let T; and T be trees of the set TREE Ty is equivalent to Tz (T, = T) if and only if for every 1 €K the equation
RESULT (Tj, @) = RESULT (T, ¢ ) holds
In the following by T; = Tz (TỊ # Tz) we denote that the tree T; is equality (inequality) to the tree T
4 Derivability for formal equations of the set TREE
Let=be a new primitive symbol We define the set EQU of formal equation for trees of the set TREE by
<equation> ; = <tree> = <tree>,
First we introduce a suitable notion of derivability for formal equations of the set EQU Let
be X ¢ EQU and TỊ = Tạ e EQU
Definition 4
Ty = Tz is derivable from X (X} Ty = Tp if and only if T) =T2 € X or Ty=T2 can be constructed in a finite number of steps using elements of X by application of the following elementary rulees inference:
RI If T € TREE then X }T=T
R2.1fX Ty = To, then Xf 1) = Ty
R3 If Xf Ty = Tz and X$ Ty = 73, then X fT, = T2
R4 If XP TL = TI, then Xf keTI,, T2> = k<TI’, T2>
RS, If X} Tz = Ty’, then XẸ k<T¡ Tạ> = k<T, Tạ >
Now we formulate the syntactic theorem of replacement
Theorem 1
For every T}, Tg, Tog, T2 of TREE holds if Ty is the result of a simultancous replacement
of the tree Tg by the tree at some places in Tp, then : X} Tg = Tyg, then X} Ty = Tp Proof Induction on the complexity of the tree Ty
5 Axiom system (AX) of the set TREE
The problem of axiomatizing the equivalent relation is fundamental for applications in practice We define the axiom system AX of the set TRE Sas follows AX:=ax) U axg U ax3 U
axg, Where we define axi (i=1,2,3,4) as follows:
50
Trang 3For each Tj, Tz , Tạ of TREE, and J
< k< TỊ, Tạ>, Tạ> = k< Ty, T3> oF
s an axiom if k s k’ Tị T;
Axiom scheme ax2
For every TỊ, Tạ , Tạ of TREE
‹<T¿,Ta>>ar
is an axiomif k>k’
kk’ €K the following formal equation
k<T}, k<Tạ, Tạ>>=k<T1,-Tạ>or TẠ:
is an axiom if k > k’
Axiom schem* axg
For each T € TREE and k € K the following
formal equation k<T,T>=T or
= T is an axiom
We can prove the following consistency theorem
Theorem 2
Let Ty and T2 be trees of the set TREE IF AX } Ty = Tg, then TỊ > Tạ
Proof By Induction on the length of a derivation from AX,
To prove the existence theorem in section 7 we formulate the following lemmas : Lemma |
For every Tj, Tz, T3 of TREE und k, kÌ eK and kek’ we have AX} k<T), k’<T9, T3>>=k'<k<T},T2>,T3>
Trang 4Lemma 2
For every Tg, Ty} of TREE, k, k’ € K and k’ >k we have AX } k< To, k’<Tg,T}>>= k'<Tọ, Tị>
Proof By using the lemma 1 The axiom scheme ax4 and the theorem 1
6.- Normal forms and uniqueness theorem
We define the following notion of a normal form of a tree of TREE
Definition 5
A tree N is said to be a normal, from if and only if
1, N =d for each d e DỲ or
2.N=kI <dl, k2<d2 ks<ds, ds+1> >0r N ky
Theorem 3 (Uniqueness theorem)
Proof For N and N° we have the
following four cases :
Case 1 N = d and N’ = d’, where dd’ ¢ Dt
Here our theorem triveally holds
Case 2 N = d and N’ = pj<dy’, pạ< dy" -Py <dy’, Wy pre?
where d’; # d’i,, for each i = 1,2, y and P1D2< <Ðy
Then we obviously obtain that N = N’
Case 3 N = ky < đị, ka<d2, k<d'e Ce batted and N’= d’ where đị # diy for every i=1,2 8 und k)<k9< <k
This case is proved analogously to case 2
Case 4: N = kị<di,ka<d2, ,k<d,, đc 2¡> > and
N’ = p,<d"), pa<d’9, “Py<d’y, V yg pre?
52
Trang 5PỊ<P2< Py:
In this case we obtain that N 2 N’ ies = y(1); kị = pị, kạ =P2« kc = py(2) and dy =ứi,
đ =đ2,-d ý = đề, địa £ đyyi G)
Let be N = N’ (4), for s andy we have the following two cases :
4l1s=y
In this case we obtain that ki = pj i = 1,2, ,8 In contrary to the above it is stated as, kịp # Pio (ig € (1,2, 8}) Let kig<pig-
The case kig>pig is proved analogously to case ki<pig,
Let Fig Pig € K and 6 ig = kige € ig = Kiog 1 Where kig = Cig < Pig and Kig <kiggy $
Dịo + kịo¿|- From the definition 2 and (4) it follows that RESULT (N, ¢ jg) = RESULT (N', Cig ) ie dig = Cyg (5) and RESULT (N, fj9) = RESULT (N’, €'i9 die digyy = jg (6)
From (5) and (6) it follows that dig = dig, and hence a contradiction, i.e in this case kj=p; for every i=1,2, ,.8 (2) From (4), (1) and (2) it follows that d) = a” dey = đyy jie N=N’
42szy
Let s<y, le y = s + r,r # 1, The case s>y is proved analogously to case s<y In thỉs case is proved analogously to ca-se 4.1: kị = pị, kạ = p2 k = pý Ớ),
Let | = pgyy and €°) = poyy Gfr>l); Ê2 = py¿¡ and Ê)2 = pyyy +1 (if r= 1) From the
definition 2 and (4) it follows that RESULT (N, ¢,) = RESULT (N’, € 1), ie dey) = d’gy1 (8)
and RESULT (N, ey) = RESULT (NI, Đế dey y= det (9), From (8) an (9) it follows that d° s+] > "49 and hence a contradiction, i.e s=y in case r>1
In this case r = 1 it follows from the definition 2, (4) that
RESULT (N, (5) = RESULT (N’, 82), ¡e doy) = oy (10) and
RESULT (N, Ê*2) = RESULT (N’, 6"), ie doy) = yg UD dp Hd gy
it follows from (10) and (11) and hence a contradiction, i¢.s = y in the case r=1 NN’ immediately follows from the case 4.1 and 4.2
7 Existence theorem and axiomatization theorem
First we will prove the theorem which says that cach tree of TREE can be uniquely ransformed into a normal form
Theorem 4 (Existence theorem)
To every tree T Ne TREE we can construct one and only one normal form N € TREE such hat T = N (1) and AXN} T = N(2)
Trang 6theorem 2 This part (2) is proved by induction on the complexity of T
Initial step
T 2d Ne D* We define N:= d and AX} T = N follows from the rule Ry
Induction step
Te k<T), Tạ> Our induction supposition yiclds AX Ty =N, (1)
AX | Ty = No (2), where the tree N; is the normal form of the tree Tị (i= 1,2) From (1 eand (2) it follows by using the rules R3, Rg and Rg that AX} T = k<Nj,Ny> For Nj and N
we have following cases:
Case 1.N, = dy, and Ny = do For AX} T=k< dị, dạ> we have the following possibilities: 1.1 dy #N d2 In this case we define N: = k<d), dy>
1.2 dy = dy In this case we define N: = Nj (or No) by using the axiom scheme ax4 an tule R3
Case 2 Ny Nz dy and Ny N= p;<djN pp<dg, Dy<dy: đài >> where đ)ị # đ;,¡ fo every i = 1, 2, V ; Py <P2< -<Py and
AX} T =k<d), py <d)N, pạ<da, ~nDy<dv, yg p> (3)
For (3) we have following case:
2.1 k<pi
2.151 đị # đ'ị Ín thịs case we define N : = k<d}, No> and AX} T = N follows from (3
by using the rules Ry and R3
212 đị = a’) We define N : = No and AX | T= N follows from (3) by using th lemma 2 and the rule Rạ
2/2 p¡ < k< Pi¿j= 1/2,.2y 1
AX} T = k<d) pigy<diyy “Pysd’y Vat > > follows from (3) by using the axion scheme ws and the rule Ry This case is proved analogously to case 2
23: k>py AX} T = k<dj, Wy 41> follows from (3) by using the axiom scheme ax3 an: the rule Ry This case is proved analogously to case 1
Case 3 Ny = q)<dy, q2 <đạ, qy<dy, dy, )> >and No Ne d, where dj #Ndi,, for every
= 1,2,.4% 3G] Sdy<- dx and AX - T = k<qy<dy, qy<d9, 04y<dy dy 4 1 > >,d>(4) For (4) we have the following cases :
3.1 k sq) AX} T = k<d), d> follows from (4) by using the axiom scheme ax and th rule R3
Trang 732 di<k š giai, = 1, 2 x1
AX } T= ay<dy qạ<d, „5 k<d(, ủ> > (5) follows from (4) by using the axiom schemes ax 1, aX} ‘he theorem 1 and the rule K3
For (5) we have the followsing 1) ases
3.2.1 diy) N# d We define N:=q) < dị, dạ <d2„ k<d;„¡, d> > and AX PT=N
follows from (5) by using the rules Riand Ra
3.22 di =d AXET= đị<di, d2<da q¡<di,dị¿¡> > (6) follows the axiom scheme
ax4 and the theorem 1
In this case we define N: = q)<d), q9<dy, 9;<dj, dj, >.> and AX} T = N follows from (6) by using the ruler Ry and Ry
3.3 k>qy AX fT = G1 <4) do<dy dy<dy, kK<dy 41, d> > follows from (4) by using the axiom scheme axy and the rule Ry
This case is proved analogously to case 3.2
Case 4 Ny = qy<dy, Gy < do dy < dy, dyyy >.> and Ny =N py<dj, p2< dạ yey < đ
dy 41> >, where dị # dị ¡ for cách ¡ = 1,2, x ¡ qị<q2< <qQx; qj #N Fiat for every j =
122
and PỊP2< -€Dy:
AX} T = k< qy<dy, qạ<d .9x<d,, Dg PP PP SD po Py< Dyed 41>)? >(7)For (7) we have the following cases:
4.1k s qị: AX } T= k<dj, py <4"), P2<d'2„ Dy<d)y, WD yg p>? follows from (7) by using the axiom scheme ax] and the rule Ry This case is poroed analogously to case 2
42 qi<k šđi¿i, 1 = 1,2, x <1
AX} T = qy<dy, 42<d2 q¡< dị, k<d¡.1, pị<d”1; P2 < a's Py<d' ys đyyi> >> (8) follows from (7) by using the axiom schemes AXỊ, 8X2 and rule Rạ
For (8) we have the following cases: `
4.2.1 k<py
4.2.1.1 địy‡# ay We define N := qi<d\, q2<d2 4¡<dị, k<dj„Ị, Pi< dị, P2< đạ, .Dy<dy, Wy gre and AX { T=N follows from the rules R, and R3
4.2.1.2 diyy=d AXP T= qy<dj, qy<dy,
PỊ<d'ị Pạ<d`
yg pe? follows from (8) by using the lemma 2 and the theorem 1
yd yr
This case is proved analogously to case 4.2
Trang 8AX} T = qy< dy, Gg < do q)<d) k< d?) Pig <d ig ye Dy<d'y, đy¿i>->> follows from (8) by using the axiom scheme ax3, the theorem 1 and the rule R3 This case is proved analogously to case 4.2
4.2.3 k 2 py
From (8) it follows by using the xiom scheme ax3 the theorem 1 and the rule Ra that: AX} T = qy<dy, d2<4› d<d, k< dy Vg re? This case is proved analogously to case 4,2
4.3 k >gy
AX | T = qi<di, q9<dy 4,<dy, k<dy 4, py <d"), P2<d"9. Py<d’y, đyyi>.>> follows from (7) by using the axiom scheme AXa, the theorem 1 and the rule Ry This case is proved analogously to case 4.2
The uniqueness it follows from the theorem 2 and 3
Now we are going to prove the completeness and axiomtization theorems
Theorem 5 (Completeness theorem)
Let T, and Ty be trees of TREE IF T, N= T3, then AX }T) = Ty -
Proof Let T, = T (1) By the theorem 4 there are normal forms Ny and No such that Ty =
Nj (2), AX -T] = Ny (3), Tp = No (4) and AX } Ty = No (5) holds From (1), (2) and (4) it follows that Ni = Ny (6) From (6) we get Nị # No by using the theorem 3 and hence rule Ry leads us to: AX} Ny = No (7) This result implies AX} T, = T2 by applying the rules Ro, Ry
to (3), (5) and (7)
Theorem 6 (Axiomatization theorem)
Let T), Tz be trees of TREE T; = Tp if and only if Ax } Ty= Tạ
Proof By using the theorem 2 and 5
8 Reduced forms and optimization theorem
First we define the following notions
For every tree T of TREE we define:
y(T) : = the number of all nodes and leafs of T and
Deep (d) : = the number of arcs of the way from the root to leaf d of T
Let R be a tree of TREE R is said to be a reduced
from of TREE
and only if R = d € Dt or R=
56
Trang 9¥ Tz9; and /Decp(dj) - Deep(dj)/ < for cách dị, dị“ + j)
Where k, ky, kz are keys of the set K and dị qj are leafs of R
Definition 7
Atree Ty of TREE i:
said to be an optinal if and only if
y(Tg) = min (y(T): T € TREE and T = Lọ]
holds
Theorem 7 : (Optimization theorem)
To each tree T € TREE we can construct one and only one reduced from R such that
2.AXEFT=R
3 (R) = min {y(I"): T’ € TREE and T’ = R}
Proof
The part (1) follows from the part (2) by N= ky
using the theorem 2 To every tree T € TREE
we can construct a normal from N such that
T = N (4) and AX ET = N (5) by using the đị kạ
IfN =de Dt, then we define R: = d and dy ‘\
here our theorem trivially holds N
IfN#de Dt ie.Neky
where dy dy on Ugyy © Dts dj # djgy for Jf
5
kyskgcncks (8 2 1)
From(6) it follows by using the
asiom scheme ax, the theorem 1,
and the rules Ry, R3 that: AX F N=
Where i= |S] and ky < < kip < kj <
King << ky
From (7) it follows by using the ky
axiom scheme ax, the theorem | and
the rule Ry in the left ~ and right dy ủ
subtrees of the sot kj :
57
Trang 10(8) kj
ke
, A,
Z\ /
Ye dar CN
i "i and kj < kị <kợi Kị.| <kj < Kiet <koy <kgyys
ky <a <kj- 1 kj <kjgy << Ri < kj < kiyi< < key <kj <kyyy < <kg
From (8) it follows in a finite number of steps by using the axiom scheme axa, the theorem | and the rule R3 that
AXE N=
5 kg
Zoe a
kj< ki <ky sky < kj <kp <kj <kp sky <kg yd dy # doi dg F dys 5 dip F dys dig, Adiga; os
deo # dsp dg # dy] and from the definition of the number i, j, £m, n, p q, it follows that,
58