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 |
1 dis a tree for vrery đe DŸ k
2 1f Ty and Tp are trees and k € K, then k,TỊ/T2>or we
is a tree qT) 2
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
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:
Trang 3For each Tj, Tz , Tạ of TREE, and J
_k’ € K the following formal equation k Tạ Tị +
< 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 z k ind k, k’ eK the following formal 7 suation k<k'<TI,Tạ>,Tạ> = k'<-TỊ, T k ‹<T¿,Ta>>ar TỊ Tạ Tạ Tạ is an axiomif k>k’ Axiom scheme ax 3 ‘
For ever Tj, T2, T3 of TREE and v =
kk’ €K the following formal equation
Tì k Tị T3
k<T}, k<Tạ, Tạ>>=k<T1,-Tạ>or TẠ: is an axiom if k > k’
T Tạ
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 |
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
Where dl,d2 ,ds+1 ¢ D+ ; di + dit] For /~\
every i=1,2 8; klk2 ks € K and dy kạ
kl<k2< <ks (s >1) ‘
We have the following theorem `
dy i
Theorem 3 (Uniqueness theorem)
Let N and N’ be normal forms € TREE If ^
N=N’, then N = N’ dg địi
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
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)
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 :
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
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
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
1.T=R ,
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ạ
theorem 4 W
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 every i= Ky, ko, wy ky € K and (6) dy dea] 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 7 % \ #
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 :
Trang 10(8) kj ke , A, Z\ / Ye dar CN § , : ` # ` X ý ` ịi Kiel ks a kN ⁄^% 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= 3 TH ee 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,
Trang 11| Deep(d) - Deep(a’) |< 1 for every d and d’ of the set (dy, d9, «+ dog 1}
In this case we define R: = the right tree of the formal equation in Figure (9) From (9) it follows AX FT=R by using (5) Ry and R3 The result (5) if and only if 3 T = Ty, T, Ty =N such that Tj = Tjy1 and AX t Tị = Tj¿ 1, j=1,2, n=1 Where, the tree Tỷ¿ | is.the result by using the axiom schemes in
the tree Tj and y(T) = y(T}) 3> Y(T2) 3s > Y(Tn)= ÁN), le y(N) = min {y(T1) y(T2) Y(Tn)} Let T; eTREE, Tị € (F), T2, Ty} and y(Tj)<y(N) (10) and Tj = NA) To Tj we can construct a normal from Nj such that Tj = Nj (12) and AX E Tj = Nj(13) by using the theorem 4 From(11) and(12) it follows that N = Nj(14) N = Nj(15) follows from(14) by using the theorem 3, ie y(N) = (Nj) (16) ` The result AX È Tị = Nị iÊ and only ¡Ê 3 Tị = T1, Tịa, j+I:J=L 2, , mel, Tim = Nj such thai Tị ~ Tịj¿¡ and AX È
where y(Tị) = y(T¡1) > y(Tịa) > > Y(Tim) = y(Nj) (17) From (16) and (17) it follows y(Tj) 2 CN) and hence a contradiction, i.e
y(N) =min { ¥(T : T’ € TREE and T’ = R } (18) For the definition of the axiom scheme axz we have y(N) = y(R) (19),and N = R it follows that
y(R)=min { y(T') : TỶ e TREE and TỶ x R } A example Let T = 5 xa 8 1 9 xe a tree of TREE, Where dị # đj for every i # j and ¡j = 1/2, 14 To this tree we can
Trang 12qy dd, ds địo dị - địa địa
where T = N x R, y(N) = +(R) = 15 = min { y(T'):T` e TREE and T’ = R } [6,7,8,9] 9 Conclusion and furthcr rcscarch
The efforts to optimize one - dimensional binary search trees as introduced in this paper are quite useful for pracical applications, especially for the representation of range queries, where the information about secondary keys defined on ranges are organized as a binary search tree
The next investigations which are in preparation are dealing with the optimization of n-dimensional binary search trees
REI 3NCES
1 Knuth, D.E : Optimum binary search trees, Acta Inf, I,1971 2, Mchthora, K : Nearly optimal binary search trees Acta Inf 5(1975)
3 Lee,C.C., Lee, D.D and Wong, C.K : Generating binary trees of bounded height Acta Inf.23
(1986), 529 - 544
4, Sprugnoli, R : The gencration of binary trees as a numerical problem J.of Association for Computing Machinery, Vol 39,2 (4.1992)
5 Thicle, H.: On equivalent transformations of one - dimensional binary search trees Pr IPL PAN, 411 (1980), 87-89
6 Do Duc Giao ; Optimization for n-dimensional Binary search trees
Twelfth European Meeting on Cybernetics and Systems Research- 1994, Vienna, Austria, 4-8 April ‘1994, Proceedings, pp.1377 - 1384
7 Do Duc Giao : General equivalence relations between the set TREE/(Formula)®, Y/, TREE/B,Y*/ and TREE/Y,Y*/
8 Do Duc Giao ; Development of TREE/ (Formula)", Y/, General equivalence relations between the sets TREE/U(Fonnula)", Y/, TREE/B,Y+/, and TREE/V, Y*/
9 Tạp chí khoa học, số 4/1993, Tr.13-17, DITTIL TIA Noi
Trang 13
VAN DE TOI UU DOI VOI CAC CAY NH] NGUYEN MOT CHIEU
Đỗ Ditc Gido * A Min TJoa Viện ứng dụng Khoa học máy tính va các hệ thông tin
Đại học Viên
Đưa ra các khái niệm về cây nhị nguyên một chiều, sự tương đương giữa các cây và khái
niệm dẫn được đối với cây
Kết quà chính là dùng hệ tiêu đề hóa đề từ một lớp phân hoạch tương đương giữa các cây, xây dựng được một cây tối ưu (duy nhất) trong lớp phân hoạch trên Thay cho việc phân loại, tÌm kiếm các thông tin trên một lớp các phân hoạch, ta chỉ cần làm việc trên cây tối ưu là đủ