• Keine Ergebnisse gefunden

Inserting a New Element into a Heap

N/A
N/A
Protected

Academic year: 2022

Aktie "Inserting a New Element into a Heap"

Copied!
25
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

deposit_hagen

Publikationsserver der Universitätsbibliothek

Mathematik und

Informatik

Informatik-Berichte 05 – 05/1981

Inserting a New Element into a Heap

Überarbeitete Fassung 1981 des

Informatik-Berichts Nr. 5 von 1980

(2)

Ernst-Erich Doberkat+

Abstract: In this paper a well known algorithm is studied which accomplishes the insertion of a new element into a heap.

Under the assumption of uniformly distributed heaps and new elements, respectively, an explicit expression for

*

the expected number of comparisons in terms of the binary representation of the number of elements in the heap is derived. From this, higher moments are calculated and asymptotically evaluated. Some numerical evidence is given that the mathematically derived results agree with results obtained in a simulation.

Some results of this paper have been presented at the 1981 Conference on Infor- mation Sciences and Systems, John Hopkins University, Baltimore.

+sponsored in part by the Institute of Educational Informatics, Forschungs- und Entwicklungszentrum für objektivierte Lehr- und Lernverfahren, Paderborn.

(3)

1. Introduction

An array A[l. .. n] of reals is said to be a heap iff A[i+2] < A[i]

holds for any i_, 2

s

i

s

n, + denoting integer division. An equivalent, and intuitively more appealing approach is the following: represent the set {1, ... ,n} as a tree in such a manner that 1 is the root of the tree, and that the node i has i+2 as its father, 2 Si sn; see Fig.1, where n=13, and the nodes are encircled. The tree just introduced will be refered to as the representation of {1, ... ,n}

as a tree. If A[i] is used as a label -of node i, then this labeling constitutes a heap iff no son has a smaller label, than its father.

-Fig.1-

This implicit data structure arises essentially in two areas:

in the field of sorting (underlying heapsort, see [10], Sec. 5.2.3), and as a priority queue with applications in such fields as graph- theoretic algorithms (see [1], p.173f) or operating systems (see [7], Sec. 6.5). In the latter context the following problem is of interest:

given a priority queue representing jobs awaiting service from some processor, and a newly arrived job which is assigned some priority, insert this job in such a manner that the priority queue structure

(4)

is not violated. Putting it in a rnore abstract setting: let

B[l ... N+l] be an array of ordered items such that B[l ... N] is a heap;

insert B[N+l] into the heap so that a heap of N+l elernents results.

Such an algorithm is investigated here with respect to its average performance. The idea is the following: consider the tree correspon- ding to {1, ... ,N}, append a new node for N+l, and search the path leading frorn N+l to the root 1 for a correct position of the new element. Then insert this new element and assign the labe1 of its father to any node on that position of the path which has been tra- versed in searching. It is then not difficult to see that this algo- rithm works as required, and that it will perform O(log N) compari- sons in the warst case.

The average behavior is far more cumbersome to deal with, and only a partial result can be given here. Consider these models:

(i) The originally heap has been constructed from independent and ,identically distributed real numbers by repeated insertion

(this is Williams' algorithm for heap construction, see [14]).

This yields a specific probability distribution on the set of all heaps with N cornponents. Assume furtherrnore that the new element is stochastically independent from the heap, and that it follows the same distribution as the originally given components.

Then the insertion process gives rise to a probability distri- bution on the set of all heaps with N+l components. Although these distributions have been identified ((5], Theorem lw), it could not yet made advantage of them for a calculation of the expected number of comparisons.

(ii) The originally given heap has been constructed using Floyd's algorithm

i~r

heap construction ([1], p.90) making the same

(5)

probabilistic assumptions, as in model (i). From these assump- tions it may be derived that any heap has the same probability to occur ([101, Theorem 5.2.3. H, [51, Theorem 1).

Unfortunately, heap insertion as considered here destroys this nice property, but we will be able to use the uniform distribu- tion of all heaps for the analysis intended.

Hence we will work here under the following assumption: any heap is assumed to have the same probability to occur, and the new element is stochastically independent from the heap and uniformly distributed, too. Having established this model, we have the opportunity to choose either a discrete or a continuous version of this model. The discrete model has already been dealt with by Th.Porter and !.Simon in [11].

Taking the expected number of levels the new element moves up the tree as the basic quantity to investigate, they derive in a purely combinatorial manner a recurrence for this expectation, and from-this recurr,ence the limiting behavior for N-00 is derived in case N, or N+l is a power of 2. But this discrete approach leaves open some questions which may be answered with a continuous model. The latter model is used to derive

- an explicit representation for the expected values in question,

- explicitely the probabilities for the number of compa- risons,

- closed forms of the exponential generating fun~tion for the higher moments of the random variable in question.

•.

Note moreover that the continuous model allows to tackle the problem from an analytical point of view by manipulating integrals and com- puttng transformations, which sometimes has some advantages over

(6)

counting the respective objects.

Let us have a short look at the contents of the paper: in Section 2, some notations are fixed, some anatomical details of heaps are quoted from [10], and the probabilistic assumptions are made more feasible.

Section 3 deals with the derivation of the expectations which we

would like to know, and reports some experimental results. Final1y in Section 4 some higher moments for the random variables in question are computed. This is done in case the new node is the left-or the rightmost node on its level, and includes some ·results from [11] as special cases. The main tool in this asymptotic analysis are complex variables, and the well known method of subtracted singularities.

This method allows to extract the asymptotic behavior of a sequence from the behavior of its generating function at its singularities, provided neither the function nor the singularities are too ill behaved.

2. Heaps

Let the space B from which all components of heaps are taken be the closed unit interval [0,1], and fix N as the number of components of the originally given heap. G

0 denotes the set of all N-dimensional vectors x E BN such that the components of x are mutual ly different and enjay the heap property. It is assumed that the heaps in G

0 are uniformly distributed. Assuming that every heap has the same proba- bility to occur means in this model that every Borel subset of G

0 is assigned its N-dimensional volume, viz., N-dimensional Lebesgue mea- sure, as the probability to occur. This must be weighted by some factor which takes care of the postulate that the sure event G

0 is

(7)

assigned probability one. In order to characterize this factor, and for later purposes, let g(N,i) be the size of the subtree rooted at i with respect to the 'great' tree having N nodes. g(N,i) may be ex- pressed explicitely: Assume that N has the binary representation /lbn_1 ... b

0/

2 (hence n = Llog 2 NJ), then Knuth calls the node

the special node on level k, and it is shown in [10], Exercise 5.2.3.20, that

g(N,/bn-1··:.bj/2) = /lbj-1··-bo/2

holds. The special nodes are geometrically distinguished in that they form the path from the rightmost node on level n, viz., N to the root 1. If i is a non-special node on level j, then we have

n-J·

g(N,i)=2 -1, if i is a right node, and

g(N,i) = 2n-j+l - 1,

if i is a left node on that level. In the sequel, however, mainly the sizes of the subtrees rooted at special nodes will of interest. Now denote by G(N,j) the product of all subtree sizes for nodes which are in the subtree rooted at the node j, i .e.,

G(N,j) :=rr{g(N,i); i is in the subtree rooted at j}, then it follows from Theorem 1 in [5], that the N-dimensional

N -1

Lebesgue measure A (G

0 ) of G

0 equals G(N,1) . The base set that will be considered is

G := {(x 1 , ... ,xN+l); (x 1 , ... ,xN) EG0 , xN+l EB, all compo- nents are mutually distinct}.

Since the new element will be assumed tobe stochastically indepen- dent from the heap, and uniformly distributed, it will be assumed that

(8)

Prob(A) := G(N,lp,N+l(A)

is the probability that the (N+l)-tuplet consisting of the heap and the element to be inserted are taken from the Borel set Ac G. The

connection of this model with the usual discrete one is the following:

Let H be the set of all permutations of {1, . . . ,N+l} such that the vector (n(l), ... ,n(N)) meets the heap condition, and define the map p:G-H by p(x) = 'IT iff X; is the n(i)-th smallest component of the vector. lt is shown now that

Prob({x; p(x) = 'JT

1}) = Prob({x; p(x) = 'IT 2}) for any n

1,'IT2 EH, hence that p induces equidistribution on H.

This is done in the following way: let K be uniquely determined per- mutation of {1, ... ,N+l} such that

'!Tl O K = 'JT2

holds, and a•ssociate with K the homeomorphism h which is defined by

then it is readily seen that (p o h)(x) = p(x) o K

hol ds for any x EG. Consequently we have wi th H 'JT. • · = {x; p(x) = n.} the J

J

following

h[H ]=H , '!Tl rr2 and

VXEG: ldet h'(x)I = 1.

Now the Change of Variable Formula applies:

Prob(H ) = G(N,1)

f

ld\N+l

rr 2 H

'IT2

= G(N,1)

f

ldAN+l h [ H ]

'lfl

(9)

2

= G(N,1)

f

1 oh• idet h1 ld>,.N+l

H

1T 1

= G(N,1)

f

ld>,.N+l H

1T 1

= Prob(H ).

1T 1

This demonstrates that the continuous model here parallels the dis- crete one, and that the results obtained here apply to that model, too.

Having made clear under what probabilistic assumptions the algorithm for insertion will be considered, it may be convenient to have the exact formulation of the algorithm:

Input: An element (x 1 , ... ,xN+l) of G, such that (x 1 , ... ,xN) is a heap.

Output: The same N+l numbers arranged as tobe a heap of N+l el.ements.

Method: O. {Initialization}

Y := xN+l; j := N+l, i := j-1-2;

1. {Search for the correct position}

whi le ( i > 0) and (y <X;) do x. :=x.; j :=i; i :=i-1-2

J 1

od;

2. {Insert}

Consider as an example in Figure 2 N = 10 and a heap of N elements taken from the natural numbers.

-

(10)

-Fig.2-

-Fig.3-

The new element 5 has tobe inserted, and this is done by comparing with 17, with 14, and with 2. 14 and 17 will be labels of the nodes 5 and 11, respectively, and 5 will replace 14 as the label of node 2.

Hence the heap constructed in this way is (with the special path w.r.t. N+l indicated by heavier lines) as in Figure 3.

(11)

3. Calculating the Expectations

Let x EG be given. In order to be able to insert xN+l at its proper place, only the labels of the special path are of interest, and this interest focusses on the position of xN+l in the chain provided by xt(N+l,l) > ... > xt(N+l,m)' where m := Llog2(N+l)J. Accordingly, we split G into sets which reflect this position: define

S ( 0) .

. - -

{ X E G; xN+l >xt(N+l,1)}'

S ( k)

. . - -

{X EG; X t ( N + 1 , k) > X N+ 1 > X t ( N + 1 , k + 1 ) } ' l::;:k::;:m-1, S(m) :={XEG; xt(N+l,m) >xn+l}.

Thus if k < m, there are k+l comparisons necessary in order to find the node which wil 1 be labeled by xN+l; if k = m, however, m compari- sons are needed, since the node 1 = t(N+l,m) has no father. Let C(x) be the number of comparisons in question, hence

-- { k+l, C(x)

m '

if xES(k) for k<m if XES(m).

Consequently the expected number E(C) equals m-1

E(C) =

h

(k+l) • Prob(S(k)) +m • Prob(S(m)) m

=

L

k • Prob(S(k)) + [1 - Prob(S(m)) ].

k=O

Hence the probabilities Prob(S(i)) should be known for Q::;:i::;:m.

First Prob(S(O)) will be calculated, t~en the other probabilities will be derived from this using the good old Change of Variables Formula from Calculus ([12], 8.27). Consider the set Y(O) of all chains down- ward,

then any number of Y(O) may serve as a special path for some x E S(O).

(12)

This observation is used to apply the well known Theorem of Fubini ([12], Theorem 7.8, p.150) on product integration:

Prob(S(O)) = G(N,l) • ;._N+l(S(O))

= G(N,l)

f

;._N-m({xEG; xt(N+l,i) =Y;,

y ( 0)

The evaluation of the latter integral requires the knowledge of the measure of the set

{xEG; xt(N+l,i)=Y;, Q:s;i~m}.

Before calculating it, it might be approporiate to adopt some geome- trical point of view. Consider the tree corresponding to {l, ... ,N+l}.

Since we are given labels of the special path, we ignore this path and cut it out for a moment. There remains from the given tree a forest of completely balanced binary trees, each of which is rooted at the brother of some special node; consider the following Figure 4 in which special nodes ~re indicated by heavy dots,and brothers of special nodes by asterisks. Now labels any of these subtrees as to become heaps, but under the constraint that the label of the respec- tive root is not greater, than the label of that special node which is the father of that root.

/

!'\ /

/\ A

. . .

'

/\ /\ ./\

- Fig.4 -

(13)

From this a heap labeling is obtained upon considering the whole tree again. Note that some nodes may be assigned the same label; But this doesn 1t matter, since it can happen only an a set with measure zero.

This idea will now be realized in three steps:

Step 1: Abbreviate for the moment by F(k,y) the set of all heaps with k elements coming from Bsuch that the label of the root is minorized by y, 0 -5:y -5: 1. Then ;\k(F(k,y)) equals

(1-y)g(k,l)/G(k,1).

This is so since F(k,y) is homeomorphic to F(k,O) by the map which maps each component xj to (xj-y)/(1-y), l -5:j -5: k, and by the Change of Variables Formula, since the Jacobian of this- transformation equals

(l-y)g(k,1)_

Step 2: Let for the moment (y0 , ••• ,ym) E Y(O)

be fixed as a vector of labels for the special path, and let <i> be the brother of t(N+l,i) for O -5: i -5:m-1 (in case N+l is even, <O> does not exist, then g(N+l,<O>) := 0,G(N+l,<O>) := 1 is defined for conve- nience). Consider the decomposition of the tree corresponding to {1, ... ,N+l} into the forest and the special path mentioned above.

Consider a heap labeling for the tree rooted at <i> such that the label of <i> is not smaller than Y;+l' Hence a member of

F ( g ( N + 1 , < i > ) ., y i + 1 ) a r i s es f o r a ny i , 0 -5: i -5: m -1. In t h i s w a y w e g et the forest labeled, and the [(N+l) - (m+l)]-dimensional volume of all these labelings amounts to

;\N-m({xEG; xt(N+l,i) = Y;, 0-5:i-.5:m})

m-1 .

=-1-1 [(1-y. )g(N+l,<i>)/G(N+l),<i>)].

i=O i+l

(14)

Step 3: Having in mind

m ( m j

f

-1-1 (1-y.)e i) dy

0 . . . dym = -,-1

[2'.

(e(i) + l)]-l Y(0) i=0 1

j=0 1=0 and canceling matching factors, we see that

_!!!_ -1

Prob(S(0)) = 11 [1 - /lc.

1 ... c /2 ],

j=l J- o

provided N+l has the binary representation /lcm-l· .. c

0/

2 . Note that

and that

hold.

i+c. •

. g(N+l,<i>) = 2 1

-1 = (l+c;) • 21 -1

k

L(g(N+l,<j>) +l) = /lck ... c

0/

2 -1 j =0

Let us turn to the case k > 0. Define Y(k) as the vector of possible labels to the special path for numbers of S(k):

y ( k) : = {y o' · · · 'y m) ; l ~ y 1 > ... > y k > y o > y k + 1 > ... > y m ~ 0} ' and

then

y ( m) · - {y o' · · · 'Y m) ; 1 ~ Y 1 > · · · > Y m > Y o ~ 0} '

Prob(S.(k))

= G(N,l) •

f

>..N-m({x EG; xt(N+l,i) =yi, 0~ i ~m )dy

0 . . . dym y ( k )

= G(N,l) • ( \N-m({xEG; xt(N+l,i) =yi+l' 0~i ~k-1, y ( 0)

xt(N+l,k) =yo, xt(N+l,j) =yj, k+l~j ~m}) x

X dy ... dy .

o m

This equation follows from the Change of Variables Formula, since the map

{

Y(0) - Y(k)

(yo,· .. ,ym) - (Y1,· .. ,yk,Yo,Yk+l'"". ,ym)

(15)

is a homeomorphism the Jacobian of which is always equal to unity.

The evaluation of this equation is easy usin0 the integral formula in Step 3. This proves

Proposition:

Let N+l have the binary representation /lcm_ 1 ... c0/ 2 .. Then

holds.

Prob(S(k)) =/lck-l'''c0/ 2 -1

lt is on the first glance rather surprising that the probabilities in question depend on the binary representation of N+l (rather than only on the length of the path or so). This might be explained by the

observation that the sizes of the subtrees rooted at the brothers of the special nodes depend on the binary representation of N+l, as indicated above, and the sizes of these subtrees affect the probabi- lities involved, as is seen from Step 2.

The proposition above implies the formula for the desired quantity:

Theorem:

Let N+l have the binary representation /lcm_1 ... c

0/

2. Then the following holds

(a) The expected number E(C) of comparisons equals

( b ) The expected number E(L) of levels the new element moves up tree equals

m i m -1

~

/lc. , - 1 ... c 0

7

2 j=i+l

-,-,

(1-/lc . 1 ... c /2 J- 0 ).

the

(16)

Proof: Part a) follows from the proposition, and part b) follows from the fact that

E(L)

m _,

=

L

k · Prob(S(k)) = E(T) - 1 + (N+l) -.

k=O

Let A(N+l) := E(L), then using the binary representation of N+l, A may be written inductively as

This is the expression derived by Porter and Simon ([11], Theorem 1 together with the first paragraph of its proof) for the expectation in questton. They derive this recurrence by considering the expected number of interchanges with respect to the tree with N+l nodes in com- parison to this expectation when having only that tree in mind which is rooted at the special node on level 1. Note that the way the pro- blem is tackled here gives an explicit expression for the probabili- ties involved; this will be of use later on.

In order to confirm this' mathematically derived result in the Theorem by some experiments, a simulation was run. This simulation randomly generated N+l real numbers in the closed interval [0,1], formed a heap from the first N numbers by means of Floyd 1s method

(hence preserving equidistribution) and inserted the (N+l)st number in the heap thus constructed. For any N the theoretically derived values are displayed in Figure 5 below, together with the average values resulting from the simulation.

(17)

N+l experimental values derived values

44 2.179 2.2679544

45 2.103 2.0675253

46 2.126 2.1225716

47 1. 924 1. 9489868

48 2.379 2.4172930

1020 2.296 2.3044823

1021 2.108 2.1068306

1022 2.164 2.1623180

1023 1. 993 1.9912033

1024 2.593 2.5975161

1025 2.409 2.3925615

1026 2.423 2.4218202

2045 2.109 2.1106887

2046 2.174 2.1661475

2047 1. 998 1.9951150

2048 2.589 2.6016186

2049 2.403 2.3967626

2050 2.431 2.4260054

2051 2.253 2.2497396

- Fig.5 - 4. Moments

Let X be an integer valued random variable on some sample space taking only nonnegative values, then

P(t) :=

L

tjProb(X = j)

J 2::0

is called the generating function for X. Now let E(Xr) = Mr be the expectation of the r th power of X, then Mr is said tobe the r th moment of X. For example if r = 2, from the second and th.e square of the first moment the variance var(X) := E(X2

) - (E(X)) 2 and the stan- dard deviation cr(X) := /var(X) are obtained. These values may be con- sidered as measures for the deviation of X from its mean. lt is well known that if the radi us of convergence for P i s G > 1, then all

moments exist, and the exponential moment generating function

CO

~ M tr/r 1

~ r . r=o

c o n ver g es f o r I t 1 < l n G , an d e qua l s P ( et ) ( [ 6 ] , Ex er c i s e XI . 7 . 2 . 4 , p. 285) .

(18)

Now let for the moment N+l = 2m+l - 1 be the rigthmost node on level m, and let· R(r,m) be the r th moment for the number of comparisons. We will obtain asymptotic estimates for R(r,m) both if r- 00 for fixed m and if m- 00 for fixed r, respectively.

Let h := 2m • (2m+l _ 1)- 1 , then m

Prob(S(k)) = 2 -k • hm

holds for Q:s;k:s;m (maintaining notations from Section 3). Let pk be the probability that exactly k comparisons are necessary, then

{

2-(k-l).h, if 1:s;k:s;m-1 m

3 • 2-m • h , i f k = m m

holds. Thus the generating function P for the number C of comparisons equals

Hence the exponential moment generating function F(t) equals F(t) = h [2

L

m ekt • 2-k + emt2-m].

m k=l

Differentiation yields

R(l,m) = hm • (4- (m+4)2-m) and

R(2,m) = hm • (12 - (m2 + 8m + 12) • 2-m).

Thus the variance of the number of comparisons equals

which converges to 2, as m-oo. This means that the number of runaways is statistically rather small. For example, the probability that

there are strictly more than, say, three comparisons is bounded from

(19)

above by R(2,m)/16~3/8 by Chebyshev 1s Inequality ([6], Section IX.6, p.233).

Since R(r,m) equals the r th derivative F(r)(O) of F at 0, see that m

R ( r, m) = h [ 2

L

k r • 2 -k + m r 2-m]

m k=l

"' 3mr(2m+l - 1), as r - 00+), when m is fixed.

The behavior of R(r,m), as m- 00 with r fixed will be a little more cumbersome to deal with. Consider first the generating function

m for the sequence

that G(z) equals

~

k 2 r -k )mElN. From [8], 6.9.2, it is inferred r

2 • [(1-z) (2-z) ]-l

f=I

{j}j ! [z/(2-z) ]j,

where

{j}

is a Stirl~~g number of the seiond kind ([9], Section 1.2.6).

G has a simple pole at z = 1 and a pole of order r+l at z = 2.

The residuum Res(G,1) at z = 1 equals r

lim (z-1) • G(z) = -2 S-- {J~}j!,

z-1

J=f

thus the latter sum has tobe evaluated. From [10], Answer to Exer- cise 5.3.1.3, p.627, we see that the exponential generating function for (

L

r {j}j ! )r~l is equal to (2 - e2 )-l and hence that we have

j=l

= r!

[i •

(ln 2)-r-l

+ Re ( 2 1r i

f

r - l c: ( r+ 1 , 1 - i 1 n 2 / ( 2 1r) ) ]

+) Gi ven sequences (an) , ( bn) of comp 1 ex numbers, an "' bn, as n - 00 means tha t a /b -1, as n-oo.

n n

(20)

where s(n,a) is Hurwitz 1s zeta function ([13], Chapter 13),

and i is the complex unit, Re denoting the real part of complex numbers. Now

H(z) := G(z) - Res(G,1)/(1 - z)

de f i n es a f u n c t i o n t hat i s anal y t i c i n I z 1 < 2 vl i t h m t h T ay l o r coefficier.t

Since

lim (1-z/2)r+lH(z)=r!

-z-2

({r} = 1 by [9], Eq. 1.2.6.44, p.67), from Darboux 1s Theorem ([2], r

Theorem 4) it is inferred that

~

kr2-k = r! [(ln 2)-r-l

k=l

+ 2 Re(2'ITi)-r-ls(r+l,1- i ln 2/(2'IT))]

+ m r 2 -m + o ( m r 2 -m) , as m - 00 • Conseq,uently we see that

-r-1 -r-1 ln2

R(r,m)=r![(ln2) +2Re(2'ITi) s(r+l,l-i2,r)]

+ 3mr 2-m-l + o(mr2-m), as m- 00 , provided r is fixed.

The method employed here is sometimes called the method of subtracted singularities. It has originally been studied in connection with the theory of Fourier series, see Darboux1s original paper for a histo- rical account and a rather elementary proof ([4], p.19f, p.53-56).

In order to have an impression of the order of magnitude of s(r+l,a) for some complex number a with positive real part let us have a look

(21)

at the generating function r ! • i;; ( r+ 1 , a ) =

for the sequence (s(r+l,a)) >l' r_

f

xr e-ax(l - e-x)-1 dx

0

Since

([13], p.266, footnote on p.265), we see that the generating function

equals

CO

T(z) := *=l Zri;;(r+l,a)

-(z-a)-1 + a-1 - f(e(z-a)•x - e-ax)(ex - 1)-1 dx,

0

the interchange of the infinite sum and the infinite integral is justified by uniform convergence, cf. [3], Art.176. Since T(z) con-

,.

ver g es f o r I z 1 < 1 a 1 , an d z = a i s a s im p 1 e p o 1 e, we i n f er t hat t h e residuum of T at z = a equals -1, thus

d

r+ 1, a) = a - r - l + o ( 1 a 1 - r) as r- 00 holds by [2], Theorem 4 (again).

Let us turn our attention to the case that N+l = 2m, hence N+l is the leftmost node on level m, and let L(r,m) be the r th moment of compa- risons. From the Proposition in Section 3 it is seen that the proba- bility generating function Pm equals

1 ___!!!_ . m k

=

>

zJ2-J -1-1 (1-2- )+zm2-m.

2

Ff

k=j

Hence

3 r -m -m

L(r,m) "'2°m (2 - 4 ),

as r- 00 , provided m is fixed. This is inferred fro~ the relationship between Pm and the exponential moment generating function, as quoted at the beginning of this Section. The limiting behavior of L(r,m) will be studied now by making m- 00 • This corresponds to a random variable C' with values in the natural numbers such that

Prob(C'=j) = 2-j+llT (1- 2-k).

k=j

(22)

Hence CI may be consi dered as the l imi t for m ... 00 of the number of comparisons in case N+l = 2m. Following [11], we define

00

D :=_I_I (1-2-J), j=l

k .

Ok :=_I_I (1-2-J), j =1

then C' has the probability generating function

00

P ( z) = D • z •

Y-

zj 2-j D: l

j =O J

00

= D•z--1-1 (1-2-jz)-l j=l

by Euler's partition formula ([10], Exercise 5.1.1.16, p.21). Since 2j+lo. / ( 2 j D . ) - 2

J + 1 J ,

as j-oo, P has 2 as its radius of convergence ([14], p,30), hence the exponential moment generating function

F(z) := P(e2)

converges the circle lzl < ln 2. Define

then

F'(O) = l+a.

1

F"(O) = l+a.f +3a.1 +a.2. Consequently

L(l,m) = 1 + a.

1 + o(l), L(2,m) = 1 + a.1 + 3a.

1 + a.

2 + o(l), as m- 00 • Numerically

a.1 = 1.6066951 .. . a.2 = 1.1373384 .. .

(a.1 is computed in [10], p.156 with an accuracy of forty places).

(23)

Hence the expected number of comparisons equals asymptotically 2.6066951. .. with an asymptotical variance of a.

1 + a.

2 = 2.7440335 ...

Since the number of comparisons differs asymptotically by 1 from the number of levels the new element moves up in the tree, this result includes Theorem 3 in [11].

In order to getan asymptotic estimate of the r-th moment L(r,00 ) of C', remember that

00

F(z) =

L

L(r,oo)zr/r!

r=O

holds, and that F may be written as F(z) = E(z) H(z),

where

z ~ -j z -1

E ( z •) : = D • e • 1 1 ( 1 - 2 e )

j=2 converges in lz1<2•ln2, and

H(z) := (1 -·e2/2)-l = (1 - exp(z-ln 2)')-l

is regular in IZI < ln 2. H may be expanded in 121 < ln 2 as

CO

where, as above

-n-1 -n-1

b n = n ! [ ( 1 n 2 ) + 2 Re ( 2 ir i ) • r; ( n + 1 , 1 -i 1 n 2 / ( 2 ir ) ) ]

Consequently, bn/bn+l converges to ln 2, as n- 00 From [2], Theorem 2 we now infer that

L(r,00)"'E(ln2)·b, r hence that

L(r,00 ) "'2r! [(ln 2)-r-l

+ 2 Re(2iri)-r-lr;(r+l,l-i ln 2/(2ir))],

as r - 00 Thus in case N+l is the leftmost node on level m the r-th mo- ment is roughly twice the r-th moment if N+l is the rightmost node on

(24)

the same level. It might be interesting to have estimates for L(r,m) (rather than for their limit L(r,00 ) ) in the same way, as for R(r,m).

Acknowledgements: The author wants to thank Philippe Flajolet, Gaston Gonnet and Reiner Kemp for some discussions on complex vari- ables.

References:

[1] Aho, A.V., Hopcroft, J.E., Ullman, J.D.: The Design and Analysis of Algorithms. Addison-Wesley, Reading, Mass., 1974

[2] Sender, E.A.: Asymptotic Methods in Enumeration.

SIAM, Review 16 (1974), 485-515

[3] Bromwich, T.J. I'A: An Introduction to the Theory of Infinite Series. Macmillan, London, 1926 (Second Edition)

[4] Darboux, G.: Memoire sur l 'approximation des fonctions de tres-grands nombres, Journal de Mathematiques (3) 6 (1878), 1-56, 377-416

[5] Doberkat, E.-E.: Same Observations on the Average Behavior of Heapsort-Preliminary Report. 21st IEEE FOCS, Syracuse, N.Y., 1980, 229-237

[6] Feller, W.: An Introduction to Probability Theory and its Applications, vol.I. John Wiley and Sons, New York, 1968

(Third Edition)

[7] Haberman, A.N.: Introduction to Operating System Design.

Science Research Associates, Chicago, 1976

[8] Hansen, E.R. ~ A Table of Series·and Products. Prentice-Hall, Englewood Cliffs, N.J., 1975

[9] Knu~h, D.E.: The Art of Computer Programming, vol. !-Fundamental Algorithms. Addison-Wesley, Reading, Mass., 1973 (Second Edition)

(25)

[10] Knuth, D.E.: The Art of Computer Programming. vol. III-Sorting and Searching. Addison-Wesley, Reading, Mass., 1973

[11] Porter, Th., Simon, I.: Random Insertion into a Priority Queue Structure. IEEE Trans. Software Engineering, SE-1 (1975),292-298 [12] Rudin, W.: Real and Complex Analysis. Tata Mc Graw Hill, New

Delhi, 1974 (Second Edition)

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

Cambridge University Press, 1927 (Fourth Edition)

[14] Williams, J.W.J.: A1gorithm 232: Heapsort. Comm. ACM 7 (1964), 347-348

Referenzen

ÄHNLICHE DOKUMENTE

Attempts to generate a new framework or new umbrella term (e.g., NPR, 2015; EdWeek, 2015) while well-intentioned, are not designed to address what we see as the

Nature (submitted) Isostructural phase transformations (ISPhTs) are particular cases of isosymmetric transformations and include discontinuous isostructural transitions

Moreover, the result in [10] addressing the existence of infinitely many weak solutions to a given initial configuration requires the initial density to be of class C 2 and the

Model I assumes that every heap has the same probability to occur, and that the element tobe inserted is equally likely tobe in one of the N intervals which

A composite consists of a rigid base, an elastic layer and a film that can be assumed to be inextensible.. What form will assume the film when trying to tear

We propose a new approach t o the regulator design problem wich is based on the weak asymptotic stability theory for differential inclusions developed by Smirnov [3]..

According to Alejandro Quiroz Flores, the modern state holds two comparative advantages over other forms of political organization — it is far better at directing large and

Political integration should pave the way for the formation of a single European army, moving beyond NATO’s “smart defense” concept to a far more efficient and legitimate