. Here I will give evidence of this fact.procedure siftdown(v:longint); var min,l,r:longint; begin l:=v*2; r:=v*2+1; min:=v; if (l <= s) and (a[l] < a[min]) then min:=l; if (r <= s) and (a[r] < a[min]) then min:=r; if min <> v then begin swap(a[min], a[v]); sift_down(min); end; end; procedure build; var i:longint; begin for i:=n downto 1 do siftdown(i); end;
elements, and
number of operator calls
(in the procedure
) when building a heap on this array. Obviously
determines the time of the procedure
which is interesting to us.
was done
operator calls
. Then his index did not exceed
.
operator calls
index
element increases at least in
time. Now let
i.e.
. Then after
we have calls
that is impossible, as in our heap
items. 
. Let an array element have an index
. There is
such that
. Then in order for the array element with the index
He took his place in the heap will need no more
calls
(by the lemma). The number of elements with such indices is the value
that when
vanishes.
the terms are zero (so the loop in the procedure
can start with
).



.
bounded above by a function that is
. So
.
there is a proportional value
.Source: https://habr.com/ru/post/195832/
All Articles