• Keine Ergebnisse gefunden

Deleting the Root of a Heap

N/A
N/A
Protected

Academic year: 2022

Aktie "Deleting the Root of a Heap"

Copied!
42
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

deposit_hagen

Publikationsserver der Universitätsbibliothek

Mathematik und

Informatik

Informatik-Berichte 19 – 06/1981

Deleting the Root of a Heap

(2)

Abstract: Using a continuous model, the average behavior of the familiar algortthm for root deletion is considered, when every heap has the same probability to occur. The analysis centers around the notion of a viable path in the tree representation, i.e. such paths the label which replaces the label of the root may be allowed to travel when the heap is reconstructed. In case the size of the heap is a power· of 2 it is shown that both the expected number of comparisons and of interchanges are asymptotically equal to the respective numbers in the worst case.

*

Fachbereich Mathematik und Informatik, Fernuniversität, Feithstr.140, D-5800 Hagen,

~-Jest Germany ( on 1 eave to the Department of Mathemati cs and Computer Sei ence, Clarkson College of Technology, Potsdam, N.Y. 13676, U.S.A.)

(3)

from an expected performance point of view. This algorithm is well known and works as follows: suppose you have a heap of size N such that the label of the root is the smallest element in this heap. If you want to extract this srnallest element, then you will copy it elsewhere, and the rightmost node that has no son will be placed at the root. Since the heap property is violated in doing this, this element will percolate the tree down, until it has reached a position in which the heap property is reconstructed. This process irnpl ies

that the second smallest element is now on top of the heap, and if the process of deleting the root and reconstructing the heap property is repeated until all elements in the heap are processed, the elements of the heap are arranged in ascending order. Thus root deletion is at the the heart of the selection phase of heapsort, and of the use of heaps as priority queues. Let us pick two applications in which root dele- tion occurs in a natural way.

Following a suggestion due to Aha, Hopcroft, and Ullman (AHU, p.174), heaps underly the classical algorithms to construct minimal spanning trees, and shortest paths, respectively, due to Dijkstra. Both algo-

(4)

rithms require the know1edge of that edge in the graph which has the lowest cost, and hence which has tobe processed next. Thus deleting the root in this situation means that the next edge will be investi- gated, and joined the spanning tree, or the path constructed so far.

In his discussion on the implementation of priority queues HabermanD.__

suggests the use of heaps as these queues (HAB, Section 6.5). Hence if we are given a set of jobs awaiting service from some fixed pro- cessor, all of them endowed with a priority, the root of the heap corresponds to that job which will be served next. In this context root del~tion means that the job in question receives its service, and that the residual jobs are arranged in such a manner that the job next tobe processed is readily available.

In this paper it is assumed that the heap that serves as an input to the algorithm is chosen at random in the sense that every heap has the same probabi1ity to occur. It turns out tobe advantegeous to assume that the elements in the respective heaps are real numbers (rather than integers in the range of 1, ... ,N), and to make use of a continuous model (rather than to work by counting permutations). This is mainly due to the fact that in a continuous model the Change of

(5)

Variables Formula is available, and this tool ·makes the analysis somewhat easier. The main idea in this analysis is to characterize those paths in the heap,the element replacing the originally given root of the heap may travel in order to reconstruct the heap property;

call such a path a viable one. After having done this characterization, it turns out to be necessary to compute the probabilities with which the element in question does indeed follow such a viable path. These probabilities are computed explicitely in terms of the binary expan- sion of N, and some intrinsic properties of the viable path, viz., the height of the subtree which is rooted at the first node on the path that is not on the special path, and the number of nodes that are on the path, but not on the special path (here the special path is the path 1eading from node N to the root of the tree). Using these probabilities and the length of the paths, the expected numbers of interchanges, and of comparisons necessary for the algorithm may be computed. This is done in case N is a power of 2, say N = 2 , andin n

this case the following is shown: the expected number of interchanges equals n - 1 + O(n/N), and the expected number of comparisons equals 2n - 1 + O(n/N). Note that the warst case is n, resp. 2n.

(6)

The plan of the paper is as follows: in Section 2, some preparations are done, in particular some anatomical details of heaps are quoted from the corresponding chapter in KN, the algorithm is given in a more formal manner, and some probabilistic assumptions are made ex- plicit. Section 3 deals with distributional aspects, it is shown how root deletion affects randomness (or equidistribution), and how the corresponding distribution looks like. In Section 4 the expectations are calculated by means of computing the probabil ities mentioned

- n

above for the general case, and then specializing to N = 2 . Calcula- ting the quantjties in question requires a little bit of a formal apparatus, the provision of which would interrupt the flow of the discussion. This is made good in an Appendix.

Since root deletion affects uniform distribution, the way to tackle the problem pursued here can be only the first step in analyzing the second phase of heapsort. Thus a suggestion for further work in this area along the lines sketched thus might be to study the probability distributions arising in iterated root deletion carefully and to de- rive from these distributions informations concerning the expected performance of heap selection. Another and more immediate suggestion

(7)

addresses the higher moments of the random variables involved.

2. Pr-eparations

AN-dimensional real array b[l ... N] is said tobe a heap iff

b[L.i/2J}<b[i] holds for any i such that 2::;i::;N. If {1, . . . ,N} is

represented as a tree such that 1 is the root, and Li/2J is the father of node i, and if furthermore b[i] serves as a label for node i, then b is a heap iff no node has a smaller label, than its father. The tree representation will be important in the sequel, and some notation will be used with respect to it.

To begin with, if 1::;i ::;N, let g(N,i) denote the size of the subtree rooted at i and let

G(N,i) :=-ll{g(N,j); j is a node in the subtree rooted a i}

be the product of the respective subtree sizes. A ~pecial node in the tree is a node which is on the path from N to the root 1; define

t(N,0) := N, and t(N,i+l) := Lt(N,i)/2J for Q::; i < Llog 2NJ, then {t(N,i); Q::;i::; Llog2NJ} constitutes the special path. Assume that

N equals 13, then the following figure displays the representing tree.

The special path is shown with heavier lines.

(8)

Let N have the binary representation (lbn--l ... b0 )2 , then it is easily seen that t(N,i) = (lbn_

1 ... b1)

2 holds, and from KN, Exercise 5.2.3.20 it is derived that we have

( 1 ) .

The following algorithm will be investigated in the sequel:

Algorithm rootdeletion:

Input:

Output:

Method:

a heap b[l. .. N]

x, the smallest element of the heap, and the heap

b[l ... N-1] which is the originally given heap with its root deleted and the heap property reconstructed

1. [Copy the root]

x-b[l]; b[l]-b[N];

- - - - - - - - - - - - - - - - - - - - - - -- - -

(9)

2. [Reconstruct]

i „ 1 ;

loop:

i6

i is no leaf and a son of i contains a greater label then i does

e.n.di

6.

the.n.

k-son of i with the smallest label;

b[i] - b[k];

; : = k;

goto 1 oop

This algorithm is a variation of Floyd's method to construct heaps (AHU,p.90), and if repeated N times, it returns the array sorted in descending order. The question which will be investigated below is the expected number of interchanges and comparisons that are neces- sary in the execution of this algorithm. In order to calculate these expectations, some preparations are needed.

It will be assumed that every heap has the same probability to occur, but rather than doing so for permutations, we take the heaps to be chosen at random from

H(N) :_={(x1, ... ,xN); Q:::;x;:::;1, the vector is a heap}.

Then to say that every heap has the same probability tobe considered as an input to the algorithm means that for any Borel set Ac H(N)

( 2) Prob(A) := xN•A (A) N

(10)

defines the probability in question. Here xN denotes the product of all subtree sizes, i.e.

xN:=-ll{g(N,i); l~i~N} ( =G ( N, 1)) ,

and AN is N-dimensional volume or,more technical, Lebesgue measure restricted

to (the Borel sets of) H(N). Equation (2) is proved in 00, Theorem 1 and reflects the fact that heap creation by rneans of Floyd's rnethod preserves equidistribution in the following sense: if any vector in [O,l]N is equally likely, this holds for any vector in H(N) after executing Floyd's algorithm forheapconstruction. Note that.Williams' originally given method does affect equidistribution (or randomness):

in 00 the corresponding distribution on H(N) is derived in terms of trees. It should be noted that the discrete case in which permutations are delt with is implicitely contained in the continuous case consi- dered here, since there exists a natural surjection from

G:={(x1, ... ,xN); 0~xi~l, xk*x.e. if k=l=l}

to the set of all permutations of {1, ... ,N}, see 00, and since

A helpful tool- for the subsequent investigations will be the Cha.nge.

o0 Va.4ia.ble.~ Fo4mula. from Integral Calculus as a generalization of

(11)

the familiar situation in case N=l, in which variables of integration are substituted. It reads as follows: let U and V be open subsets of

]RN, such that U = g[V] for some continuously differentiable homeomor- phism g, then we have for any integrable map <P: U- lR the equal ity

( 3) /Jd>..

f

N = V<P

1

o.g • ldet 91 ld>.. .

·

N

This formula is proved in RU,8.27. Intuitively, g may be thought to represent some algorithm which transforms some input domain U in a unique way to an output range V. Then this formula tells us haw the correspanding distribution will be transformed under the algorithm.

Finally it will be convenient to describe the way b[N] percalates the tree by a ward vE {0,1}*, where O means that it is interchanged with a left son, and 1 denotes an interchange with a right san. Let far such a v be vj the prefix of length j, i.e. if v=c 1 ... ck' 1::;j::;k, then vj = c

1 ... cj; far the sake af completeness v0 is defined as the empty ward e. Given such a word v, let Z(v) be the endnode of the

path represented by v, i .e., if s(v) is the value of the binary number

(12)

corresponding to v (e.g. s(000 101) = (101)

2 = 5), then Z(v) := 21V1+s(v).

3. Distributional Aspects

Let for v E {0,1}* as the path to be followed H(N,v) be the set of all xEH(N) such that the N-th component xN does indeed follow v. Hence xEH(N,v) holds iff

holds for l~j ~ lvl. Thus if xEH(N,v), then xN will be interchanged with Xz(vj) for l~j ~ lvl, but it will not be interchanged with any

son of Xz(v)' provided there is one. Now call v a viable ~ath for xN iif H ( N , v ) =!= 0, an d den o t e t h e s et o f a 1 1 v i ab 1 e p a t h s b y V N . Note t hat not every path in the tree corresponding to {1, ... ,N} starting at 1 can be a viable path for N: any part bn-i · .. bj of the special path excluding LN/2J mu~t not be a viable path. This is so because the heap property implies that

is true for l~j~n-1, hence if xN would stop at (lbn_ 1 ... bj) 2 , this would imply

(13)

which is clearly a contradiction. On the other hand, bn-l" .. b

1 con- stitutes a viable path, and it is easily seen that v E VN holds iff both Z(v) ~ N - 1, and v

$

{b n-1 ... b.; 2 l ~ i ~ n-1} are true. Note that H(N) equals the disjoint union of H(N,v) for v E VN.

Oenote the action of the algorithm by TN, hence TN maps H(N) into G(N-1), where

In order to describe the distributional effects of TN, some subsets of G(N-1) will be needed; these subsets will depend on viable paths for N and will shown to be the bijective images of the sets of the form H(N,v). Ta begin with, let

G(N-1, bn_ 1 ... b1) := G(N-1),

and if v is a viable path which does not stop in LN/2J, then

is defined. Consider for example the case N = 6, and X:= (1/5, 1/3, 1/4, 1/1, 1/2, 1/6), then XE G(S,v) for v = 0, 00, 01, 1. X is dis- played in the following figure with t~e mentioned paths indicated by heavier lines.

(14)

lt will be seen in a rnornent that X lies in the image of exactly the classes H(N,O), H(N,00), H(N,01), and H(N,l) under TN.

3.1 Lemma:

G i v e n v E V N , T N : H ( N , v ) - G ( ,J -1 , v ) i s a b i j e c t i o n .

Proof: 1. lt is easily seen that TN is one to one, when restricted to H(N,v) since TN operates on all elements in H(N,v) as the same permutation of coordinates. The crucial step is to show that TN is onto, and this is done by constructing a preirnage for an arbitrarily chosen z E G(N-1,v) and showing that x E H(N,v). Define x in the

following rnanner:

xl := YN•

x ·=y Q:s;j :s; lvl-1, Z(vj+l). Z(vj)'

XN :=Yz(v)

x . :

,

= y. , ·

,

o t h e rw i s e.

Then TN(x) =Y, and x is a mernber of H(N). For if there exists an

(15)

index i such that x .

12 > x., at least one of the indices must be in

L 1 J 1

A := {Z(vj); O~j ~ lvl} u {N}, since outside of this set nothing is changed. Now working through all possible combinations (viz.,

{Li/2J,i}cA, Li/2JEA~i, iEA~Li/2J) demonstrates that the assump- tion leads to a contradiction, hence shows that xEH(N). Moreover x is easily seen tobe a member of H(N,v), since Yz(v) >yLN/ 2 J iff

At the first glance it is not clear what connection between 3.1 and the task of analyzing the algorithm may be constructed. An immediate consequence is the following: given z E G(N-1), the number of v E VN

with z E G(N-1,v) counts the number of possible heaps which are mapped by TN to z. From this observation the distribution of TN may be

derived now. Oefine for z E G(N-1)

M(z) := card({v E VN; z E G(N-1,v)})

where l(A;•) is the indicator function of the set A, i .e.

l(A;x) = {

1, if xEA, 0, otherwise.

(16)

3.2 Proposition:

Given a Borel set Ac G(N-1), let

µ ( A ) : = P ro b ( T N E A )

be the probability that the output of the algorithm is an element of

A. Then

( 4 )

holds.

µ(A) = xN • Jt•1(z) dz A

Proof: 1. We demonstrate a seemingly sharper result, viz., that

( 5)

f

fdµ =

G(~-1)

xN·

f

f(z) M(z) dz · G(~-1)

holds for any f: G(N-1) -IR which is measurable and bouncted. Since the

indicator function l(A;•) of the Borel set A has these properties,

and since plainly

J1(A;•) dµ=µ(A),

the desired equality (4) is obtained from (5).

2. We have postulated that

. N

Prob(B) = XN. A (B)

holds for every Borel set B cH(N), and from this we have

(17)

j

fdµ=xN·

f

f(TN(x)) dx

G(N-1) H(N)

= L{xN·

f

f(TN(x)) dx; v E VN}

H(N-1,v)

= L{xN·

f

f(z) dz; v E VN}.

G(N-1,v)

since by 3.1 TN[H(N,v)] = G(N-1,v). Hence the Change of Variable Formula implies

r

f(TN(x)) jdet TN(x)j dx H(~,v)

=

j

f(z) dz.

G(N-1,v)

Now jdet TN(x)j is always equal to 1, because TN permutes only coor- dinates, has thus the determinant of a permutation matrix as its

. -

Jacobian. If now the observation

j

f(z) dz =

j

f(z) l(G(N-1,v);z) dz

G(N-1,v) G(N-1)

is applied, and the definition of M as well as the additivity of the integral is taken into account, the equal ity (5) is proved. O

Denote by T(x) the number of interchanges which are necessary to re- c o n s t r u c t t h e h e a p p r o p e r t y w h e n t h e r.o o t o f x E H ( N ) i s de l e t e d . Thus T(x) equals lvl whenever xEH(N,v), and we have for the

(18)

expectation [(T)

If S(x) is the number of comparisons which are done in reconstructing the heap property for x E H(N), and if x E H(N,v) for v E VN, such that Z(v) has i sons (Q:::;i:::;2) in ttie tree corresponding to {1, ... ,N-1 },

thenS(x)=21vl+i holds. Hence Eq.(6r) implies

IE(S) = 2·1E(T) + b

0 ·x •1-N(H(N,bn-l···bi)) + N

+ 2·xN • L{1-N(H(N,v)); Z(v) has two sons w.r.t. {1, . . . ,N-1}}.

The second surnmand comes from the observation·that bn-l" .. b1 is the only viable path which ends in a node with exactly one son, provided b0 = 1; in case b

0 = 0, i .e. if N is even, this path ends in a leaf w.r.t. {1, . . . ,N-1}.

Frorn Eqs (6) it is seen that it will be necessary to compute 1-N(H(N,v)) for vEVN. This will be done in the next Section.

(19)

4. Computing the Expectations

Fix for the moment a viable path v E VN. Then from Lemma 3.1 and from the proof of Proposition 3.2 it is clear that

holds. Now let yE [0,1[ be fixed, and let

(x1, ... ,xN-l) E G(N-1,v) (y) iff

then Fubini 1s Theorem (RU,p.150f) implies 1

Let

:i.. N ( H ( N , v ) ) =

r

;i._ N -l ( G ( N - 1 , V ) ( y ) ) dy .

)

0

be the set of all (N-1)-heaps in which the label of node Z(v) is greater than the label of LN/21; for the sake of completeness

is defined. Then

G(N-1,v)(Y) (y + x

1(1-y), ... ,y + xN-l(l-y))

constitutes a differentiable homeomorphism with Jacobian (1-y)N-l_

(20)

Thus we have

( 7)

1

\N(G(N-1,v)) = \N-l(K(N-1,v)) • j(l-y)N-l dy

0

= { \N-l(K(N-1,v)),

and the task of computing \N(G(N-1,v)) is reduced to that of computing

- .

this is done easily, since the respective sets equal H(N-1), which has XN-1 -l as its (N-1)-dimensional volume. In the general case, how- ever, some hairy computations will be needed. We will proceed as

follows: to begin with, we fix labels an the special path with respect to N, but excluding N, and on the nodes of v. With these fixed labels in mind we have a look at the volume of all heaps which may have these labels at the respective nodes; then we will integrate over all

possible values which may be fixed and obtain in this way the

(N-1)-dimensional volume of K(N-1,v) by means of Fubini's Theorem.

By the latter Theorem, we have

\N-l(K(N-1,v))

= f/l-l-n({xEK(N-1,v); xt(N,i) =y; for l~i ~n}).

l~yf:::: ... ~y n~O.

(21)

Thus for a fixed chain l2::y12:: ··· 2::yn2::0 the (N-1-n)-dimensional volume

N-1-n

:\ ({xEK(N-1,v); xt(N,i) =Y; for l:::;;i :::;;n})

of all those heaps in K(N-1,v) that are labeled on their special path by this chain should be known.

Let us have a look at a possibility to obtain a heap labeling in K(N-1,v), when the special path {t(N,i); l:::;;i :::;;n} (excluding N, of course) has already a label. First, we cut the path {t(N,i); l:::;;i :::;;n}

out of the tree representing {l, ... ,N-1} and are left with a forest .

of smaller trees. These trees are all rooted at the brothers of the special nodes t(N,n-1), ... ,t(N,l), and of t(N,O), if N is odd. The following figure might help to clarify things (the nodes

t(N,l), ... ,t(N,n) are marked by heavier dots, the respective brothers by asterisks, and the path v in question by heavy lines).

(22)

Now consider a tree in this residual forest with the property that no part of v is in it. This tree may be labeled as a heap under no other constraint, than that the label of its root is not smaller, than the label of its father (in the 1big 1 tree). All trees but one are labeled in this manner. The remaining one contains that part of the path v which lies not on the special path. In order not to come in conflict with the heap property the root is- labeled as are the roots of the other trees, viz., with a number not smaller than the label of its father. But in order not to come into conflict with the requirement that the heap thus produced is a member of K(N-1,v), the endnode is assigned a number that is not smaller, than y1. Having in mind these restrictions and repeating the considerations from above, this yields a labeling of this subtree, too. Now we must make sure that the described labeling procedure may be traced probabilistically.

It will be helpful to have the following formulae at our disposal

(8)

with 0 :S z :S 1. In case z = 0, Eq (8) refl ects the fact that heap con- struction with Floyd's algorithm preserves equidistribution, in case

(23)

z = 1 both sides are zero, hence the case 0< z< 1 must be considered.

Since the set in question is the image of H(k) under the map

the Jacobian of which is (1-z)k, the equality follows immediately from the Change of Variables Formula.

If s(i) ~0, f(i), := s(i) + 1, Os;a, ss; 1, we have

( g)

et. a

k

= ~

(-l)a-1(1-s)s(l)+ .. +s(a)(l-o.)E(a+l)+ .. +E(k)

a a k t

f

-1 1

L s (

i ) ] • [ -1 1

.L e (

i ) ] r=l 1=r t=a+l 1=a+l

(this formula will be proved in an appendix, since a proof would inter- rupt the flow of the discussion rather severe).

In carrying out the program sketched above, it will be necessary to compute the contribution of certain subtrees to the measure

AN-l(K(N-1,v)). This is done in the next lemma.

4.1 Lemma:

Let P1, ... ,Pr be a path in a complete binary tree

r

of depth s (hence

T has m := 2s-l nodes) such that P1 is the root of T. Then the

(24)

m-dimensional Lebesgue-measure of all those heap labelings for T such that the label for P1 in not smaller, than a prescribed Y1 E [0,l]

and the label for Pr is not smaller, than a given Y2 E [0,1] equals TT(2s+l-i)_l)

i=l

( 2s-r+a_ 1 ) 2(s-r)(r-1) TT (r 2t_ 2a) t=l

t*a

Proof: 1. Remember that heaps must not have components outside the closed interval [0,1]. Let Y; be a label to node P; such that

0~yl~ .. ~Yr~l, and let 0; be the brother o~ P;, 2~i ~r. Then the Lebesgue measure of all possible heap labels which respect y1 , ... ,Yr equals

r-1 )

-1-1 (1-y.)g(m,Qi+l

r .

1 1

1 =

-11 g(m,P;) • - - - -

i=l G(m,P1)

This is easily deduced from Eq(8), since only the subtrees of T, which are rooted at the nodes

O;,

and the subtrees of T which are rooted at the left, or the right son of Pr' have tobe taken into consideration. Moreover it is noted that

r-1 r

G(m,P1) = -11 g(m,P 1 ) • -11 G(m,Q;) · G(m,Pr)

i=l i=2

holds.

(25)

2. The equality in question is now proved by an application of Eq(9) with ß =

v

2 , a

=

Yl' X;= Yr+l-i, e:(i)

=

g(m,Qr+ 2-i) if i 2: 2, and

e:(1) = g(m,Pr) - 1. The looked for measure equals the integral over (*) with respect to all Yl'··••Yr• which satisfy

Y2:s;yr:s;l, Yr-1 :s;yr,

or, equivalently

Y2:s;yr:s;l, Y1 :s;yr-1 :s;yr, Y1 :s;yr-2 :s;yr-1, Y1:s;y1:s;Y2·

In evaluating sums involving E(i), it is tobe noted that

( 2s+l-i n

g m,P;) = g(m,Q;) = -1. u

- Now let us return to our fixed path v, and let us note some characteri- stica associated with it:

*

P(v) is the smallest index j such that bn-l ... bj is a prefix of v,

*

p(v) is the number of nodes which are on v but not on the special path bn_ 1 ... b0 ,

(26)

~ R(v) is the number of nodes which are an the path from the end- node of v to a leaf including that endnode.

Hence we see that

R(v) = P(v) - p(V) + bp(v)-1"

The viable path v may be written as v=bn-1···bP(v) d1···dp(v)' where ct

1

*

bP(v)-l" Note that the case P(v) = n is not excluded. More- over

cr(v) := R(v) + p(v) - 1

is the number of nodes in a path starting from (lbn_ 1 ... bP(v)d 1)2 to a leaf (including its start node), thus the tree rooted at

(lbn-l" .bP(v)d1)2 has 2cr(v) - 1 nodes. Consider as an example N = 52 and the path v = 1001:

(27)

In the tree displayed the Special path 10100 is characterized by

smal 1 dots, the path v by heavier l ines. We have n = 5, P(v) = 3 (since 10 is a prefix of v, but 101 is not), R(v)

=

2, cr(v)

=

3, p(v)

=

2.

Now let T; be that son of the special node t(N,i) which is different from t(N,i-1), 2~i ~n; in case N is odd, the node t(N,0) has a brother,

-- --· ·..., •..

too, hence T

1 is definea. In case N is even, however, care must be taken since T

1 is not defined, but for the sake of convenience

is defined in this case.

Now let Y; be a fixed label of t(N,i) for 1 s i s n such that 1 ~y

1 ~ ... ~Yn ~ 0. The contribution of the subtree rooted at the node T; to the volume of all those heaps which have y1, ... ,yn as the labels is

(l-y.)g(N-1,T;)

1

G.( N-1 , T; ) in case i *P(v), and

p ~ ) ( ) 1 . II (

iJ

v + -1 -l)

i=l

~

a=l

(28)

in case i = P(.v). In the latter case the subtree rooted at TP(v) takes over the role of Tin Lemma 4.1, and the path mentioned there is that part of v which is not on bn-l' .. b1. Consequently the heap labelings that are considered must satisfy the condition that the label of the root TP(v) is not smaller, than yP(v) (otherwise the heap condition

is violated), and that the label of the endnote (lbn_ 1 ... bP(v)d 1 ... dp(v))2

is not smaller, than y1 (otherwise the defining condition for

K(N-1,v) would be violated). The case i

*

P(v) is treated by means of Eq.(8), since any labeling of the subtree rooted at Ti which satisfies the heap condition is constrained only by the property that the label of Ti must not be smaller, than Y; is. In passing note that

g(N-1,T.)

,

= g(N,T.),

,

holds for all i, since no T. is a special node with respect to

,

{1, . . . ,N}.

From Fubini 1 s Theorem now it is inferred that

(29)

;i._N-l(K(N-1,v)) =

p+r) (

2 <J ( V ) + 1 - i

; = 1

- - - x

n

-II G(N,T.) . 1 1 1 =

x P

:r: [ (

2 cr ( v ) -p ( v ) + a -1 ) • 2 ( cr ( v ) -1 ) ( p ( v ) -1 ) •

i-r.) (

2 t -2 a)] -1 x

a = 1 t=l

t=i=a

where the exponents n(a,i) are defined by

g(N,Tl) + 2cr(v)-p(v)+a - 1, ; = 1 n ( a , i ) . - ;- 2 cr ( v ) -P ( v ) ( 2 P ( v ) ~ 2 a ) , i = P ( v )

g(N,T;), otherwise

Now it is not difficult to see that

1 1 1 n .

j

d x n

J

d x n _ 1 . . .

j

r d x 1 ,· l=ll ( 1 -- x ; ) y(i) = - , n 1 [

L

, y ( j ) ] - 1

i=i j=l

O xn x 2

holds, where y(i) ~O, y(i) = y(i)+l, as above. In order to evaluate the integral above, note that

i-l+b. l

g(N,T;)=2 1 - -1

and

holds. Since

(30)

L...

t ii(a,i) =

i = 1

the Lebesgue measure in question equals

pj_v) .

l l (2cr(v)+l-,_l) i=l

2(cr(v)-l)(p(v)-l).

This expression may be si~plified a little bit by nothing that both

n n

xN =_-II G(N,T;)·-11 g(N,t(N,i)),

l=l i=l

and

cr(v) = P(v) - 1 + bP(v)-l ho 1 d.

Substituting these values, we see that the probability for the path v tobe followed does depend only on its characteristics cr(v) and p(v), and not on, say, the number of times it turns left of right or on an- other geometrical characterization relative to the tree.

For the rest of this paper we will assume that there is n such that N

(31)

equals 2n, i.e. that N is the leftmost node on level n, and denote by p(r,s) the probability that xN follows a path v that has the charac- teristicscr(v)

=

s and p(v)

=

r, hence

1 n . p(r,s) = N- -11 21

i=l

r 1 . -11 (25+ -1-1) i=l

x 2-(s+l)•(r-l).

f-[ !f (

2s+l-a+ 2j_2 )

TT(

2-t_ 2-a)(l

a=f

J=o t=l

t=1=a

holds, since b. = 0, 0:::; i:::; n-1. There are 2r-l paths with this charac-

1

teristics and any of them has length n - s - 1 + r. Thus the expected number [(T) of interchanges equals

n-1 s r-1 . 1

[(T) =

Y- L

2 • (n-s-l+r) •p(r,s) + 0(-N) 's;-r r=l

since r may take values between 1 and s, and s may range from 1 to n-1.

The O(N-l) term takes into account that parts of the special path with respect to N that are viable paths. Specializing formula (B) in the Appendix to

where s is fixed for the moment, we see that

*=l

s 2r-l(n-s-l+r)•p(r,s)

equals

(32)

where

and

1 n . s . s

:= N- --II 21 ·{25 -II (1-2-1 ) ~ f ( )

i=l i=l

~

a •

lt is not difficult to see that

thus

~

n-1 is derived, and

remains tobe evaluated. Formula (C) in the Appendix shows that we have

where

thus

t - ; -1

-11 (1-2 ) = F• (l-yt), i=l

F :=-11 (1-2-i )-l,

; 2!: 1

~ i •t i -1 Yt : = ~ [2 •1•3• .. •(2 -1)] ,

'l 2!: 1

(33)

n-1 -1 -1

L

B1(s) = N •F•(l-y )•(n-l)•F •(N+O(l))

s=l n

is derived using

-1 -s -s -s

(1-y) s =1+2 +4·4 +C•8

for some constant C, ICI :s; 2.

This proves

4.2 Theorem:

In case N = 2n root deletion requires

(n-1)·(1-y )+0(-) n

n N

interchanges on the average.

Let us turn our attention to the .number S of necessary comparisons.

The equation (6) above tells us that we shou1d have a look at those paths which end in a node that has exactly two sons with respect to the tree representing {1, . . . ,N-1}. No such path v will have the characteristic cr(v) = 1, or p(v) = a(v), thus

( 10)

n-1 s-1

L L

2r-1 p(r,s)

s =2 r= 1

should be known. An argumentation very close to that in the proof of (B) in the Appendix shows that

(34)

( 10 1 ) s-1

~=l 2r-1 p(r,s)

1 n .

= N- · -1 1 2J x

j=l

) ( s ks 2s-a s . s 1

x {f(l • 2 -1) - a-- f(s+l-a) •2 -11 (1-2-1) • [ -11 (l-2t-a) ( }

i =1 t=l

t=!=a

holds, where f is as above. The evaluation of the latter sum requires the knowledge of

s ( 11 )

~

=

2!, J

z.

r

[(25+1 .z)5 s+l -II (1-2t•z)]- 1 dz t=l

(for some reale,

1 e 1 < 1)

where the contour r of integration is given in the following figure.

Here s>O is arbitrary, and 0<n<2-(s+l) holds.

(35)

By making M,K - 00 , applying Jordan's Lemma (WW,6.222,p.115) together with the addivity of the integral, we see that the 1atter integral reduces to

e

- "@

f

IZl=n

2-(s+l)•s.z-(s-1)[ s+l -11 (1-2t•z)]-l dz.

t=l

Since O is the only singularity of the integrand (in fact, it is a pole of order s-1), the integral equa1s the residuum of it at zero.

From CHR, Exercise 21.8,p.344, it is seen that s+l -11 (l-2t•Z)-l =

t=l

and from the Cauthy-d'Alembert test (WW,p.30) we infer that the series converges in IZI < 2-(s+l). Consequently, the integral

equals

1

2TTT

J

IZl=n

z-(s-l) - , s+l , (l-2tz)-l dz t=l

Hence the sum in Eq (11) is 0(2- 25 ). Plugging this into Eq (10' ), it is now clear that this sum equals

-1 -1 s -1 -s

N •(l-y ) s •(l-y )·(2 -l)+N n ·0(2 ).

This implies that we have for the sum in Eq. (10)

(36)

n-1 s-1

> s:7"2"

~

f;;-r

2 r-1 •p(r,s) = N ·(1-yn)•(N+O(l)) -1

=l+O(-N). 1

Since the latter sum equals the contribution of all those paths which have exactly two endnodes in the tree corresponding to {1, ... ,N-1}, we may conclude from Eq (6s)·

Corollary:

In case N = 2n root deletion requires

comparisons on the average.

Appendix

In order not to interrupt the discussions above, some formulae have not been accompanied by a proof. This is now the place to give these proofs.

To begin with, the following integral formula wi 11 be proved ( A)

1 x,l

xf

1

J

d x l J d x

z .. j

d-x k

·ff

(1-x-)e:(i) . 1 1

1 =

ß a. a.

=L

k

a=l

(-l)a-l(l-s)s(l)+ .. +s(a)(l-a.)s(a+l)+ .. +s(k)

a a k t

[ -11

L

s(i)J·[ -11

z:==

s(i)J

r=l 1 =r t=a+l i =a+l (with s(i) :=e:(i)+l, e:(i);?:0 for 1::;i::;k).

(37)

The proof of (A) proceeds by induction on k, starting at k = 2. In this case we have

and this implies the desired equality for k=2. Before establishing the inductive step, define Fk+l(E:(1), ... ,E:(k+l)) as the integral to be evaluated, and Gk+l(E:(1), ... ,E:(k+l)) as the corresponding sum on the ri ght hand. Oenote in a formal s um

S=a1 + •.. +am the j th summand aj by [j ]S.

The induction hypothesis gives Fk+l(E:(1), ... ,E:(k+l)) =

= s ( k + 1 ) - l • (1-et)

s (

k + l ) • G k ( E:( 1) , ... , E:( k) ) - s(k+l)- 1 -Gk(E:(1), ... ,E:(k-1),E:(k)+s(k+l))

k - -1 s(k+l) ·

·=

L

E: ( ~ + 1 ) • ( 1- et ) , [ a ] G k ( E: ( 1 ) , ... , E: ( k ) )

.. a=l ·

k .

-L

s(k+l)- 1 [aJ Gk(E:(l), ... ,E:(k-1),E:(k)+s(k+l)).

a=l

The following relations are not too difficult to establish:

(i) - s(k+l)-l•[k] Gk(E:(1), ... ,E:(k-1),E:(k)+s(k+l)) k+l k+l

= (-l)k+l-1.(1-ß)s(l)+ ... +s(k)+s(k+l). [ - , , ~ s(i)]-1 r= 1 , = r

= [k+l] Gk+l(E:(l), ... ,E:(k),E:(k+l)),

(38)

( i i ) e(k+l)-l•(l-a)e(k+l).[1] Gk(e(l), ... ,E(k)) -e(k+l)-l·[l] Gk(e(l), ... ,E(k) +e(k+l))

= e(k+l)-l·(l~ß)E(l).(1-a)e(l)+ ... +e(k+l) X

_!__ t -l k-1 t k+l _1

x[(e(l)• II

L

E(i)) -(E(l)•{ II Le(i)}·{>e(i)}) ]

t=2 i =2 t=2 i=2

1=2

= (1] Gk+l(E(l), ... ,E(k+l)),

(iii: for l<a<k, the following equality holds

( i V)

e(k+l)-l•(l-a)e(k+l).[a] Gk(E(l), ... ,e(k)) -e(k+l)- 1 [a] Gk(E(l), ... ,E(k-1) ,E(k) + e(k+l)) ' = [a} Gk+l (E(l), ... ,E(k+l)),

= [l(] Gk+l(E(l), ... ,E(k+l)).

Putting together these equa 1 i ti es, the 1 ooked-for i denti ty F k+l = Gk+l is established. D

(B) Let f:IR - IR be a map, n,s EIN such that n 2:s, then we have

f-f-

r-1 ( . ....L s+1-i (s+l)(r-1) ....L ( -t -a ]-1

'r=I~ f(s+l-a)•2 • n-s-l+r)•{ il=ll (2 - -1)·[2 ~~l 2 -2 ) } t=t:a

s . s s-a ( ) 1

s s - -1 - -t - a-1 -

= (n-1)·(2 -l)•f(l) - 2 11 (1-2 ) x L f(a)•[ 11 (1-2 )•(l-2 )] .

i=l a=2 t=l

(39)

The proof of this clumsy, but useful equality rests on the following

Observation:

Let k E IN,

then we have

k-1

·-

~

. -

r=

r exp(r•z) -11

t=l

Fk(ln 2) = cS 1 , k '

k-2 .

F

k (

l n 2 )

= ( -

jl

='i (

1- 2 -J ) ) • ( 1- cS 1 , k ) (where cS is of course Kronecker's symbol).

Proof of the Observation: From CHR, Example 2 in §30.2,p.340 (an iden- tity due to Cauchy) we see that

~ l z -t Fk(z) = 11 (1-e •2 )

t=l

holds, and that we consequently have

Now (B) may be proved, observing that the expression in braces equals

s r s-r . 1

2s+l-a. - , 1 (1-2-i)·[ -11- (l-2t-a)· -11 (1-2-1) ] -

i=l t=l i=l

t=1=a

Interchanging the summations with respect to a, and r, changing the summation index a to s+l-a, and canceling, it is seen that the sum in

(40)

question equals

x ((n-a) Fa(1n 2) + F~(ln 2))

From this and the observation above the asserted equality follows.

In the above application of (B) we had s+l-a

f(s+l-a) =<JJ(2 ),

where <Pisa meromorphic function on the complex numbets with simple poles only in Rez52-(s+l)_ In addition

holds uniformly in arg z, as z - 00 • The temptation is nearly over- whelming to tackle the inner sum over a by the Residue Theorem:

~

r

= -

f(s+l-a)[

TI

(2-t-2-a)J-l t=l

t*a 1

J

<P(2s+l.z) 21T i r di,

(2-t-z) C -II

t=l

where Cis a simple closed curve which lies in Re z >2-(s+l) having the zeroes of the denominator in its interior. From this it may be shown that the sum in question equals

O+ioo

- 2;i J

dz,

0-; 00

(41)

where 2-(s+l) <0<2-r, by Jordan's Lemma. It might be interesting to know whether this approach yields a more elegant way to evaluate the sums in question.

Finally, let's prove the equality ( C )

-m · -k -1

11 (1-2 ) =F•(l-y ).

k=l m

From CHR, Exercise 21.8,p.344, we infer Euler's identities

m .

1 00 n

-11 (1-x1 )- = 1 + ) xn •-11

i=l ,i-;-r t=l

1 m+i-1 -x

1-x 1

Specializing to x =½ and applying Cauchy's identity used in the proof of the observation above, we see that.

m . 1

F- -II (1-2-1 ) - i=l

00 n 2n(n-1)/2

2k(k+l)/2

= ) ) m•k n•k n

'n;-rw 2 -2 .1.3 ... -(2 -1)

Interchanging the summation w.r.t. n and k, then replacing n by n+k (thus summing from n = 0 to 00 instead of summing from n = k to 00 ) , evaluating and cancelling some terms shows that the latter double sum equals

= F•y . m

(42)

1

1.

RefeY-ences

AHU Aho, A.V., HopcY-oft, J.E. Ullman, J.D.: The Design and Analysis of ComputeY- Algorithms. Addison-Wesley, Reading, Mass., 1974

CHR Chrystal, G.: Algebra - An Elementary Text-Book, part II.

Chelsea Publishin.g Company~ New York, 1964 (Reprint, Seventh Edition)

00 Doberkat, E.-E.: Some Observations on the Average Performance of Heapsort-PY-eliminary Report. 21st FOGS, Syracuse, N.Y.:.,1980, 229-237

HAB Habermann, A.N.: Introduction to Operating System Design. Science Research Associates, Chicago, 1976

KN Knuth, D.E.: The Art of Computer Programming - vol .3, Sorting and Searching. Addison-Wesley, Reading, Mass., 1973

RU Rudin, W.: Real and Complex Analysis. Tata McGraw Hill,

·New Delhi, 1974 (Second Edition)

ww

Whittaker, E.T., Watson G.N.: A Course of Modern Analysis.

Cambridge University Press, Cambridge 1927 (Fourth Edition)

· ..

'.:_,.:,::.,::_)\

{ .. : ,;/ .\.'·:::\

! ,'i

; ., H :: f: "::: ti .,-. !~

: · .. :: ,1 r

~ .·:, ~.

~\r·i /r.' ;

'·-t~~,-'.':

,.,~:-'<'.:

Referenzen

ÄHNLICHE DOKUMENTE

GENERATION OF VALUE- ORIENTED SCORING RULES.. Ah Introduction to Bayesian Inf erence

In this paper, I examine the root cause of sovereign default on the basis of a model of inflation that is built on a micro- foundation of government behavior and conclude that the

To study the sediment structures, a special survey system is installed on board of Polarstern, the sub-bottom profiler Parasound, which transmits special sonar signals to the

Second, because paid apps are important to smartphone users, using paid apps for free is a main reason for jailbreaking, a reason more decisive among Android users than Apple

Similarly, we cannot reject the unit root null hypothesis for BAL when the per capita GDP is considered and, consequently, we should conclude that there is no common trend in

The argument of the method Draw(&#34;AP&#34;) is important here. It tells the TGraphPainter class to show the axes and to plot mark- ers at the x and y positions of the specified

The argument of the method Draw(&#34;AP&#34;) is important here. It tells the TGraphPainter class to show the axes and to plot mark- ers at the x and y positions of the specied

We use a new approach to upscale root biomass of trees at the global scale (Supplement, Fig. S1) based on machine learn- ing algorithms trained by a large dataset of in situ